Last active
January 18, 2016 15:15
-
-
Save kassy-kz/aaaef7f741599d325dd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<LatLng> decodePoly(String encoded) { | |
List<LatLng> poly = new ArrayList<LatLng>(); | |
int index = 0; | |
int len = encoded.length(); | |
double lat = 0, lng = 0; | |
while (index < len) { | |
int b, shift = 0, result = 0; | |
do { | |
b = encoded.charAt(index++) - 63; | |
result |= (b & 0x1f) << shift; | |
shift += 5; | |
} while (b >= 0x20); | |
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); | |
shift = 0; | |
result = 0; | |
do { | |
b = encoded.charAt(index++) - 63; | |
result |= (b & 0x1f) << shift; | |
shift += 5; | |
} while (b >= 0x20); | |
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); | |
lat = (double)dlat / 100000; | |
lng = (double)dlng / 100000; | |
LatLng p = new LatLng(lat, lng); | |
poly.add(p); | |
} | |
return poly; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment