public static List<LatLng> decodePolyLines(String poly){
int len = poly.length();
int index = 0;
List<LatLng> decoded = new ArrayList<LatLng>();
int lat = 0;
int lng = 0;
while (index < len){
int b;
int shift = 0;
int result = 0;
do{
b = poly.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lat += dlat;
shift = 0;
result = 0;
do {
b = poly.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
}while (b >= 0x20);
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >>1));
lng += dlng;
decoded.add(new LatLng(
lat/100000d,
lng/100000d
));
}
return decoded;
}
您可以使用此功能來解碼折線和創造的經緯度
謝謝,那麼自己的算法是唯一的方法嗎? – StackoverflowForResult