Google Directions API 中路线编码解析

 public List<Location> GetGeoPoints(string encoded)
{
List<Location> poly = new List<Location>();
int index = , len = encoded.Length;
int lat = , lng = ;
while (index < len)
{
int b, shift = , result = ;
do
{
b = encoded.ToCharArray()[index++] - ;
result |= (b & 0x1f) << shift;
shift += ;
} while (b >= 0x20);
int dlat = ((result & ) != ? ~(result >> ) : (result >> ));
lat += dlat; shift = ;
result = ;
do
{
b = encoded.ToCharArray()[index++] - ;
result |= (b & 0x1f) << shift;
shift += ;
} while (b >= 0x20);
int dlng = ((result & ) != ? ~(result >> ) : (result >> ));
lng += dlng; double latResult = ((double)lat / 1E5) * 1E6 * Math.Pow(, -);
double lngResult = ((double)lng / 1E5) * 1E6 * Math.Pow(, -);
Location p = new Location(latResult, lngResult);
poly.Add(p);
}
return poly;
}
上一篇:http协议中content-length 以及chunked编码分析


下一篇:HTTP协议中的chunked编码解析