Example #1
0
      public Marker(PointLatLng pos, MarkerType type, MarkerColor color)
      {
         this.Position = pos;
         this.Type = type;
         this.Color = color;
         this.Text = string.Empty;
         this.TooltipMode = MarkerTooltipMode.OnMouseOver;
         this.Visible = true;
         this.CustomMarkerAlign = CustomMarkerAlign.MiddleMiddle;
         this.CustomMarkerCenter = Point.Empty;

         this.IsMouseOver = false;
         this.ToolTipOffset = new Point(14, -44);
      }
Example #2
0
 static PointLatLng()
 {
    Empty = new PointLatLng();
 }
Example #3
0
 public static PointLatLng Subtract(PointLatLng pt, SizeLatLng sz)
 {
    return new PointLatLng(pt.Lat + sz.HeightLat, pt.Lng - sz.WidthLng);
 }
Example #4
0
 public static PointLatLng Add(PointLatLng pt, SizeLatLng sz)
 {
    return new PointLatLng(pt.Lat - sz.HeightLat, pt.Lng + sz.WidthLng);
 }
Example #5
0
 public SizeLatLng(PointLatLng pt)
 {
    this.heightLat = pt.Lat;
    this.widthLng = pt.Lng;
 }
Example #6
0
 public bool Contains(PointLatLng pt)
 {
    return this.Contains(pt.Lat, pt.Lng);
 }        
Example #7
0
      // .
      // |
      // unsure ends here

      public void Offset(PointLatLng pos)
      {
         this.Offset(pos.Lat, pos.Lng);
      }
Example #8
0
 public RectLatLng(PointLatLng location, SizeLatLng size)
 {
    this.lng = location.Lng;
    this.lat = location.Lat;
    this.widthLng = size.WidthLng;
    this.heightLat = size.HeightLat;
 }
Example #9
0
      /// <summary>
      /// gets lat & lng from geocoder url
      /// </summary>
      /// <param name="url"></param>
      /// <returns></returns>
      internal PointLatLng? GetLatLngFromGeocoderUrl(string url, bool useCache)
      {
         //GET /maps/geo?q=lietuva%20vilnius&output=csv HTTP/1.1  
         //User-Agent: Opera/9.62 (Windows NT 5.1; U; en) Presto/2.1.1 
         //Host: maps.google.com  
         //Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
         //Accept-Language: en,lt-LT;q=0.9,lt;q=0.8     
         //Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1 
         //Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0 
         //Cookie: PREF=ID=dc739bf01aeeeaf6:LD=en:CR=2:TM=1226264028:LM=1227458503:S=nShNvvvFhVPickBv; NID=17=l4NuFqggqPCBRcQu4BLw5EkBfiTej5k3i8gPOWl16_wqWNaYA5tepmtdKpxBqxkqDWZV5NIn9DaQQcpbyL4T8mDDmkoMuIMh71nasewOVxAZFWFkzrRGU3kDu_QBTmDt
         //Cookie2: $Version=1 
         //Connection: Keep-Alive, TE   
         //TE: deflate, gzip, chunked, identity, trailers

         //HTTP/1.1 200 OK   
         //Content-Type: text/plain; charset=UTF-8 
         //Content-Encoding: gzip
         //Date: Sat, 13 Dec 2008 12:30:38 GMT
         //Server: mfe 
         //Cache-Control: private, x-gzip-ok="" 
         //Content-Length: 47
         //..........320.1.15.3..4134.12.32..453...l5W....

         PointLatLng? ret = null;
         try
         {
            string urlEnd = url.Substring(url.IndexOf("geo?q="));

            char[] ilg = Path.GetInvalidFileNameChars();
            foreach(char c in ilg)
            {
               urlEnd = urlEnd.Replace(c, '_');
            }

            string geo = useCache ? Cache.GetGeocoderFromCache(urlEnd) : string.Empty;

            if(string.IsNullOrEmpty(geo))
            {
               HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
               request.ServicePoint.ConnectionLimit = 50;
               request.Proxy = Proxy != null ? Proxy : WebRequest.DefaultWebProxy;

               request.UserAgent = "Opera/9.62 (Windows NT 5.1; U; en) Presto/2.1.1";
               request.Timeout = Timeout;
               request.ReadWriteTimeout = Timeout*6;

               //request.Accept = "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1";
               //request.Headers["Accept-Charset"] = "utf-8, utf-16, iso-8859-1, *;q=0.1";
               //request.Referer = "http://maps.google.com/";
               request.KeepAlive = true;

               using(HttpWebResponse response = request.GetResponse() as HttpWebResponse)
               {
                  using(Stream responseStream = response.GetResponseStream())
                  {
                     using(StreamReader read = new StreamReader(responseStream))
                     {
                        geo = read.ReadToEnd();
                     }
                  }
               }

               // cache geocoding
               if(useCache)
               {
                  Cache.CacheGeocoder(urlEnd, geo);
               }
            }

            // parse values
            // true : 200,4,56.1451640,22.0681787
            // false: 602,0,0,0
            {
               string[] values = geo.Split(',');
               if(values.Length == 4)
               {
                  if(values[0] == "200")
                  {
                     double lat = double.Parse(values[2], CultureInfo.InvariantCulture);
                     double lng = double.Parse(values[3], CultureInfo.InvariantCulture);

                     ret = new PointLatLng(lat, lng);
                  }
               }
            }
         }
         catch(Exception ex)
         {
            ret = null;
            Trace.WriteLine("GetLatLngFromUrl: " + ex.ToString());
         }
         return ret;
      }
Example #10
0
      /// <summary>
      /// makes url for routing
      /// </summary>
      /// <param name="start"></param>
      /// <param name="end"></param>
      /// <param name="language"></param>
      /// <param name="useHighway"></param>
      /// <returns></returns>
      internal string MakeRouteUrl(PointLatLng start, PointLatLng end, string language, bool avoidHighways)
      {
         string highway = avoidHighways ? "&mra=ls&dirflg=h" : string.Empty;

         return string.Format("http://maps.google.com/maps?f=q&output=dragdir&doflg=p&hl={0}{1}&q=&saddr=@{2},{3}&daddr=@{4},{5}", language, highway, start.Lat.ToString(CultureInfo.InvariantCulture), start.Lng.ToString(CultureInfo.InvariantCulture), end.Lat.ToString(CultureInfo.InvariantCulture), end.Lng.ToString(CultureInfo.InvariantCulture));
      }
Example #11
0
 /// <summary>
 /// makes url for reverse geocoder
 /// </summary>
 /// <param name="pt"></param>
 /// <returns></returns>
 internal string MakeReverseGeocoderUrl(PointLatLng pt, string language)
 {
    return string.Format("http://maps.google.com/maps/geo?hl={0}&ll={1},{2}&output=csv", language, pt.Lat.ToString(CultureInfo.InvariantCulture), pt.Lng.ToString(CultureInfo.InvariantCulture));
 }
Example #12
0
 /// <summary>
 /// get pixel coordinates from lat/lng
 /// </summary>
 /// <param name="p"></param>
 /// <param name="zoom"></param>
 /// <returns></returns>
 public Point FromLatLngToPixel(PointLatLng p, int zoom)
 {
    return FromLatLngToPixel(p.Lat, p.Lng, zoom);
 }