public void Find(GeoCodeSearchResult item) { //var c = new Point(item.Location.Longitude, item.Location.Latitude); //double dis = Distance(item.Box.North, item.Box.East, item.Box.North, itemwm.Box.West, 'K'); var wm = new WebMercator(); var e = (Envelope) wm.FromGeographic(new Envelope(item.Box.West, item.Box.North, item.Box.East, item.Box.South)); //var e = new Envelope(item.Box.West, item.Box.North, item.Box.East, item.Box.South); //e.SpatialReference = new SpatialReference(4326); AppState.ViewDef.NextEffect = true; AppState.ViewDef.MapControl.Extent = e; SelectedLocation = item.Name; //AppState.ViewDef.ZoomTo(new KmlPoint(c.X, c.Y), dis*1000); }
public void ParseResult(string res) { if (res != string.Empty) { try { Result.Clear(); XDocument doc = XDocument.Parse(res); XElement kml = doc.Elements().First(); string status = kml.Element("status").Value; if ( status == "OK") { foreach (XElement xe in kml.Elements("result")) { var gcsr = new GeoCodeSearchResult { Name = xe.GetFirstElement("formatted_address").Value }; XElement ed = xe.GetFirstElement("geometry"); if ( ed != null) { XElement llb = ed.GetFirstElement("viewport"); XElement sw = llb.Element("southwest"); XElement ne = llb.Element("northeast"); { double north = Convert.ToDouble(ne.Element("lat").Value,CultureInfo.InvariantCulture); double south = Convert.ToDouble(sw.Element("lat").Value,CultureInfo.InvariantCulture); double west = Convert.ToDouble(sw.Element("lng").Value,CultureInfo.InvariantCulture); double east = Convert.ToDouble(ne.Element("lng").Value,CultureInfo.InvariantCulture); gcsr.Box=new LatLonBox(north,south,east,west); Result.Add(gcsr); } } //string [] locs = xe.GetFirstElement("Image").GetFirstElement("coordinates").Value.Split(','); //if (locs.Count() ==3) //{ // gcsr.Location = new KmlPoint { Latitude=(float)Convert.ToDouble(locs[1],CultureInfo.InvariantCulture), // Longitude=(float)Convert.ToDouble(locs[0],CultureInfo.InvariantCulture),}; // Result.Add(gcsr); //} } } } catch (Exception e) { Logger.Log("Geocoding", "Error doing geocoding request : " + e.Message, "", Logger.Level.Error); } NotifyOfPropertyChange(() => Result); } }