public Location getGeoLocation(Geo g) { //http://maps.google.com/maps/api/geocode/xml?latlng=40.714224,-73.961452&sensor=false string request = "http://maps.google.com/maps/api/geocode/xml?"; request += "latlng=" + g.getLatLng() + "&" + "sensor=" + g.getSensor(); //read in xml XmlDocument xdoc = new XmlDocument(); xdoc.Load(request); XmlNode node = xdoc.DocumentElement; XmlNodeList nodeLongAddrCol = node.SelectNodes("//formatted_address"); XmlNodeList nodeShortAddrCol = node.SelectNodes("/GeocodeResponse/address_component[type=route]"); Location loc = new Location(); loc.setDisplay_address(nodeLongAddrCol.Item(0).InnerText); double lat = g.getLat(); double lng = g.getLng(); loc.setCoords(lat + "," + lng); loc.setLat(lat); loc.setLng(lng); return(loc); }
public Location getLocation(Geo g) { try { string request = "http://maps.google.com/maps/api/geocode/xml?"; request += "address=" + g.getAddress() + "&" + "sensor=" + g.getSensor(); //read in xml XmlDocument xdoc = new XmlDocument(); xdoc.Load(request); XmlNode node = xdoc.DocumentElement; XmlNodeList nodeLongAddrCol = node.SelectNodes("//formatted_address"); Location loc = new Location(); loc.setDisplay_address(nodeLongAddrCol.Item(0).InnerText); string lat = node.SelectNodes("//location/lat").Item(0).InnerText; string lng = node.SelectNodes("//location/lng").Item(0).InnerText; loc.setCoords(lat + "," + lng); loc.setLat(Convert.ToDouble(lat)); loc.setLng(Convert.ToDouble(lng)); return loc; } catch (NullReferenceException) { return null; } }
public Location getLocation(Geo g) { try { string request = "http://maps.google.com/maps/api/geocode/xml?"; request += "address=" + g.getAddress() + "&" + "sensor=" + g.getSensor(); //read in xml XmlDocument xdoc = new XmlDocument(); xdoc.Load(request); XmlNode node = xdoc.DocumentElement; XmlNodeList nodeLongAddrCol = node.SelectNodes("//formatted_address"); Location loc = new Location(); loc.setDisplay_address(nodeLongAddrCol.Item(0).InnerText); string lat = node.SelectNodes("//location/lat").Item(0).InnerText; string lng = node.SelectNodes("//location/lng").Item(0).InnerText; loc.setCoords(lat + "," + lng); loc.setLat(Convert.ToDouble(lat)); loc.setLng(Convert.ToDouble(lng)); return(loc); } catch (NullReferenceException) { return(null); } }
private void genMap(double lat, double lng) { p = new Point(); currMap = new Mapping.Map(); currMarker = new Mapping.Marker(); mu = new Mapping.MapUtils(); gu = new Mapping.GeoUtils(); g = new Mapping.Geo(); g.setLatLng(lat + "," + lng); g.setLat(lat); g.setLng(lng); currCentre = gu.getGeoLocation(g); //update start location object startLoc.setLat(currCentre.getLat()); startLoc.setLng(currCentre.getLng()); startLoc.setCoords(currCentre.getCoords()); startLoc.setDisplay_address(currCentre.getDisplay_address()); startLoc.setReady(1); currMap.setMapType("hyb"); currMap.setCenter(currCentre.getCoords()); currMap.setSensor("false"); currMap.setSize(480, 300); currMap.setZoom(zoom.ToString()); currMap.clearMarkers(); currMarker = new Mapping.Marker(1, "red", "S", startLoc.getCoords()); if (destLoc.getReady() == 1) { currMarker = new Mapping.Marker(1, "yellow", "D", startLoc.getCoords()); } currMap.setMarkers(currMarker.toString()); pictureBox1.Image = mu.getMapImage(mu.generateMap(currMap)); pictureBox1.Refresh(); //update location textbox tbLoc.Text = startLoc.getDisplay_address(); }
public Location getGeoLocation(Geo g) { //http://maps.google.com/maps/api/geocode/xml?latlng=40.714224,-73.961452&sensor=false string request = "http://maps.google.com/maps/api/geocode/xml?"; request += "latlng=" + g.getLatLng() + "&" + "sensor=" + g.getSensor(); //read in xml XmlDocument xdoc = new XmlDocument(); xdoc.Load(request); XmlNode node = xdoc.DocumentElement; XmlNodeList nodeLongAddrCol = node.SelectNodes("//formatted_address"); XmlNodeList nodeShortAddrCol = node.SelectNodes("/GeocodeResponse/address_component[type=route]"); Location loc = new Location(); loc.setDisplay_address(nodeLongAddrCol.Item(0).InnerText); double lat = g.getLat(); double lng = g.getLng(); loc.setCoords(lat + "," + lng); loc.setLat(lat); loc.setLng(lng); return loc; }