Created
November 19, 2015 10:08
-
-
Save maxdeepfield/6949279e4687ad364eb7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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