Esempio n. 1
0
        private double measurePositionDelta(RoutePoint one, RoutePoint two)
        {
            var lat1 = one.Lat;
            var lon1 = one.Lon;
            var lat2 = two.Lat;
            var lon2 = two.Lon;


            var R    = 6378.137;          // Radius of earth in KM
            var dLat = lat2 * Math.PI / 180 - lat1 * Math.PI / 180;
            var dLon = lon2 * Math.PI / 180 - lon1 * Math.PI / 180;
            var a    = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
                       Math.Cos(lat1 * Math.PI / 180) * Math.Cos(lat2 * Math.PI / 180) *
                       Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
            var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
            var d = R * c;

            return(d * 1000);            // meters
        }
Esempio n. 2
0
        public static List <RoutePoint> DecodeGooglePolyline_Alternative(string encodedPoints)
        {
            if (encodedPoints == null || encodedPoints == "")
            {
                return(null);
            }
            List <RoutePoint> poly = new List <RoutePoint>();

            char[] polylinechars = encodedPoints.ToCharArray();
            int    index         = 0;

            int currentLat = 0;
            int currentLng = 0;
            int next5bits;
            int sum;
            int shifter;

            try
            {
                while (index < polylinechars.Length)
                {
                    // calculate next latitude
                    sum     = 0;
                    shifter = 0;
                    do
                    {
                        next5bits = (int)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 = (int)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);
                    RoutePoint p = new RoutePoint();

                    p.Lat = Convert.ToDouble(currentLat) / 1000000.0;
                    p.Lon = Convert.ToDouble(currentLng) / 1000000.0;
                    poly.Add(p);
                }
            }
            catch (Exception ex)
            {
                // logo it
            }
            return(poly);
        }