Created
February 18, 2016 17:21
-
-
Save heytherewill/a72b3a2593a3dd39cca4 to your computer and use it in GitHub Desktop.
Decode a Polyline String in Xamarin.Android
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
private IEnumerable<LatLng> DecodePolylineString(string encodedPath) | |
{ | |
var len = encodedPath.Length; | |
var index = 0; | |
var lat = 0; | |
var lng = 0; | |
while (index < len) | |
{ | |
var result = 1; | |
var shift = 0; | |
int b; | |
do | |
{ | |
b = encodedPath[index++] - 63 - 1; | |
result += b << shift; | |
shift += 5; | |
} while (b >= 0x1f); | |
lat += (result & 1) != 0 ? ~(result >> 1) : (result >> 1); | |
result = 1; | |
shift = 0; | |
do | |
{ | |
b = encodedPath[index++] - 63 - 1; | |
result += b << shift; | |
shift += 5; | |
} while (b >= 0x1f); | |
lng += (result & 1) != 0 ? ~(result >> 1) : (result >> 1); | |
yield return new LatLng(lat * 1e-5, lng * 1e-5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment