Skip to content

Instantly share code, notes, and snippets.

@kassy-kz
Last active January 18, 2016 15:15
Show Gist options
  • Save kassy-kz/aaaef7f741599d325dd5 to your computer and use it in GitHub Desktop.
Save kassy-kz/aaaef7f741599d325dd5 to your computer and use it in GitHub Desktop.
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