Skip to content

Instantly share code, notes, and snippets.

@maxdeepfield
Created November 19, 2015 10:08
Show Gist options
  • Save maxdeepfield/6949279e4687ad364eb7 to your computer and use it in GitHub Desktop.
Save maxdeepfield/6949279e4687ad364eb7 to your computer and use it in GitHub Desktop.
decode: function (encoded, precision) {
precision = Math.pow(10, -precision);
var len = encoded.length, index = 0, lat = 0, lng = 0, array = [];
while (index < len) {
var b, shift = 0, result = 0;
do {
b = encoded.charCodeAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
lat += ((result & 1) ? ~(result >> 1) : (result >> 1));
shift = 0;
result = 0;
do {
b = encoded.charCodeAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
lng += ((result & 1) ? ~(result >> 1) : (result >> 1));
array.push([lat * precision, lng * precision]);
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment