Skip to content

Instantly share code, notes, and snippets.

@heytherewill
Created February 18, 2016 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heytherewill/a72b3a2593a3dd39cca4 to your computer and use it in GitHub Desktop.
Save heytherewill/a72b3a2593a3dd39cca4 to your computer and use it in GitHub Desktop.
Decode a Polyline String in Xamarin.Android
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