thank you very much, you have helped me a lot, I am currently working with xamarin and use this method to decode polyline.
private List<LatLng> DecodePolyline(string encodedPoints)
{
if (string.IsNullOrWhiteSpace(encodedPoints))
{
return null;
}
int index = 0;
var polylineChars = encodedPoints.ToCharArray();
var poly = new List<LatLng>();
int currentLat = 0;
int currentLng = 0;
int next5Bits;
while (index < polylineChars.Length)
{
// calculate next latitude
int sum = 0;
int shifter = 0;
do
{
next5Bits = polylineChars[index++] - 63;
sum |= (next5Bits & 31) << shifter;
shifter += 5;
}
while (next5Bits >= 32 && index < polylineChars.Length);
if (index >= polylineChars.Length)
{
break;
}
currentLat += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);
// calculate next longitude
sum = 0;
shifter = 0;
do
{
next5Bits = polylineChars[index++] - 63;
sum |= (next5Bits & 31) << shifter;
shifter += 5;
}
while (next5Bits >= 32 && index < polylineChars.Length);
if (index >= polylineChars.Length && next5Bits >= 32)
{
break;
}
currentLng += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);
var mLatLng = new LatLng(Convert.ToDouble(currentLat) / 100000.0, Convert.ToDouble(currentLng) / 100000.0);
poly.Add(mLatLng);
}
return poly;
}