javascript - Get North,South,East,West street names from Geocode in Google Map -
i have implemented property search through google maps , each property marked pin in google map. in need, user can able know street names of single property (geocode) north, south, east, west, northeast, northwest, southwest , southeast directions.i need list out each direction street names.
for example searching below property has return
property : 18,maha street,coimbatore,tamilnadu (27.268255,-95.55666)
north : main street south : anna street east : river road west : school street northeast : kmskj street northwest : ring road southwest : hasbdagh road southeast : outer ring road
is possible achieve in google map. please me out.
if geocode direction can apply reverse geocode right?
i have achieved server side geocode process, below methods involved:
public geocoderlocation locate(string query) { geocoderlocation n = new geocoderlocation(); geocoderlocation s = new geocoderlocation(); geocoderlocation e = new geocoderlocation(); geocoderlocation w = new geocoderlocation(); geocoderlocation ne = new geocoderlocation(); geocoderlocation nw = new geocoderlocation(); geocoderlocation se = new geocoderlocation(); geocoderlocation sw = new geocoderlocation(); webrequest request = webrequest .create("http://maps.google.com/maps/api/geocode/xml?sensor=false&size=750x700&address=" + httputility.urlencode(query)); using (webresponse response = request.getresponse()) { using (stream stream = response.getresponsestream()) { xdocument document = xdocument.load(new streamreader(stream)); list<xelement> longitudeelement = document.descendants("lng").tolist(); list<xelement> latitudeelement = document.descendants("lat").tolist(); if (latitudeelement != null && latitudeelement.count == 3 && longitudeelement != null && longitudeelement.count == 3) { ne.longitude = double.parse(longitudeelement[1].value, cultureinfo.invariantculture); ne.latitude = double.parse(latitudeelement[1].value, cultureinfo.invariantculture); sw.longitude = double.parse(longitudeelement[2].value, cultureinfo.invariantculture); sw.latitude = double.parse(latitudeelement[2].value, cultureinfo.invariantculture); nw.latitude = ne.latitude; nw.longitude = sw.longitude; se.latitude = sw.latitude; se.longitude = ne.longitude; } list<geocoderlocation> nlist = new list<geocoderlocation>(); nlist.add(ne); nlist.add(nw); n = getcentralgeocoordinate(nlist); list<geocoderlocation> slist = new list<geocoderlocation>(); slist.add(se); slist.add(sw); s = getcentralgeocoordinate(slist); list<geocoderlocation> elist = new list<geocoderlocation>(); elist.add(se); elist.add(ne); e = getcentralgeocoordinate(elist); list<geocoderlocation> wlist = new list<geocoderlocation>(); wlist.add(nw); wlist.add(sw); w = getcentralgeocoordinate(wlist); string address_shortname = string.empty; string address_country = string.empty; string address_administrative_area_level_1 = string.empty; string address_administrative_area_level_2 = string.empty; string address_administrative_area_level_3 = string.empty; string address_colloquial_area = string.empty; string address_locality = string.empty; string address_sublocality = string.empty; string address_neighborhood = string.empty; string address_streetname1 = string.empty; string address_streetname2 = string.empty; string address_streetname3 = string.empty; string address_streetname4 = string.empty; string address_streetname5 = string.empty; string address_streetname6 = string.empty; string address_streetname7 = string.empty; string address_streetname8 = string.empty; if (n != null) { string str = reversegeoloc(n.longitude.tostring(), n.latitude.tostring(), out address_shortname, out address_country, out address_administrative_area_level_1, out address_administrative_area_level_2, out address_administrative_area_level_3, out address_colloquial_area, out address_locality, out address_sublocality, out address_neighborhood,out address_streetname1); txtnorth.text = address_streetname1; } if (w != null) { string str = reversegeoloc(w.longitude.tostring(), w.latitude.tostring(), out address_shortname, out address_country, out address_administrative_area_level_1, out address_administrative_area_level_2, out address_administrative_area_level_3, out address_colloquial_area, out address_locality, out address_sublocality, out address_neighborhood, out address_streetname2); txtwest.text = address_streetname2; } if (s != null) { string str = reversegeoloc(s.longitude.tostring(), s.latitude.tostring(), out address_shortname, out address_country, out address_administrative_area_level_1, out address_administrative_area_level_2, out address_administrative_area_level_3, out address_colloquial_area, out address_locality, out address_sublocality, out address_neighborhood,out address_streetname3); txtsouth.text = address_streetname3; } if (nw != null) { string str = reversegeoloc(nw.longitude.tostring(), nw.latitude.tostring(), out address_shortname, out address_country, out address_administrative_area_level_1, out address_administrative_area_level_2, out address_administrative_area_level_3, out address_colloquial_area, out address_locality, out address_sublocality, out address_neighborhood, out address_streetname4); txtnorthwest.text = address_streetname4; } if (ne != null) { string str = reversegeoloc(ne.longitude.tostring(), ne.latitude.tostring(), out address_shortname, out address_country, out address_administrative_area_level_1, out address_administrative_area_level_2, out address_administrative_area_level_3, out address_colloquial_area, out address_locality, out address_sublocality, out address_neighborhood, out address_streetname5); txtnortheast.text = address_streetname5; } if (se != null) { string str = reversegeoloc(se.longitude.tostring(), se.latitude.tostring(), out address_shortname, out address_country, out address_administrative_area_level_1, out address_administrative_area_level_2, out address_administrative_area_level_3, out address_colloquial_area, out address_locality, out address_sublocality, out address_neighborhood,out address_streetname6); txtsoutheast.text = address_streetname6; } if (sw != null) { string str = reversegeoloc(sw.longitude.tostring(), sw.latitude.tostring(), out address_shortname, out address_country, out address_administrative_area_level_1, out address_administrative_area_level_2, out address_administrative_area_level_3, out address_colloquial_area, out address_locality, out address_sublocality, out address_neighborhood, out address_streetname7); txtsouthwest.text = address_streetname7; } if (e != null) { string str = reversegeoloc(e.longitude.tostring(), e.latitude.tostring(), out address_shortname, out address_country, out address_administrative_area_level_1, out address_administrative_area_level_2, out address_administrative_area_level_3, out address_colloquial_area, out address_locality, out address_sublocality, out address_neighborhood, out address_streetname8); txteast.text = address_streetname8; } } } return null; } public geocoderlocation getcentralgeocoordinate(ilist<geocoderlocation> geocoordinates) { if (geocoordinates.count == 1) { return geocoordinates.single(); } double x = 0; double y = 0; double z = 0; foreach (var geocoordinate in geocoordinates) { var latitude = geocoordinate.latitude * math.pi / 180; var longitude = geocoordinate.longitude * math.pi / 180; x += math.cos(latitude) * math.cos(longitude); y += math.cos(latitude) * math.sin(longitude); z += math.sin(latitude); } var total = geocoordinates.count; x = x / total; y = y / total; z = z / total; var centrallongitude = math.atan2(y, x); var centralsquareroot = math.sqrt(x * x + y * y); var centrallatitude = math.atan2(z, centralsquareroot); return new geocoderlocation { latitude = centrallatitude * 180 / math.pi, longitude = centrallongitude * 180 / math.pi }; } public static string reversegeoloc(string longitude, string latitude, out string address_shortname, out string address_country, out string address_administrative_area_level_1, out string address_administrative_area_level_2, out string address_administrative_area_level_3, out string address_colloquial_area, out string address_locality, out string address_sublocality, out string address_neighborhood, out string address_streetname) { address_shortname = ""; address_country = ""; address_administrative_area_level_1 = ""; address_administrative_area_level_2 = ""; address_administrative_area_level_3 = ""; address_colloquial_area = ""; address_locality = ""; address_sublocality = ""; address_neighborhood = ""; address_streetname = ""; xmldocument doc = new xmldocument(); try { doc.load("http://maps.googleapis.com/maps/api/geocode/xml?latlng=" + latitude + "," + longitude + "&sensor=false"); xmlnode element = doc.selectsinglenode("//geocoderesponse/status"); if (element.innertext == "zero_results") { return ("no data available specified location"); } else { element = doc.selectsinglenode("//geocoderesponse/result/formatted_address"); string longname = ""; string shortname = ""; string typename = ""; bool fhit = false; xmlnodelist xnlist = doc.selectnodes("//geocoderesponse/result/address_component"); foreach (xmlnode xn in xnlist) { try { longname = xn["long_name"].innertext; shortname = xn["short_name"].innertext; typename = xn["type"].innertext; fhit = true; switch (typename) { //add whatever looking below case "country": { address_country = longname; address_shortname = shortname; break; } case "locality": { address_locality = longname; //address_locality = shortname; //om longname visar sig innehålla konstigheter kan man använda shortname istället break; } case "sublocality": { address_sublocality = longname; break; } case "neighborhood": { address_neighborhood = longname; break; } case "colloquial_area": { address_colloquial_area = longname; break; } case "administrative_area_level_1": { address_administrative_area_level_1 = longname; break; } case "administrative_area_level_2": { address_administrative_area_level_2 = longname; break; } case "administrative_area_level_3": { address_administrative_area_level_3 = longname; break; } case "route": { address_streetname = longname; break; } default: fhit = false; break; } } catch (exception ex) { return null; } } return (element.innertext); } } catch (exception ex) { return null; } } [serializable] public class geocoderlocation { public double longitude { get; set; } public double latitude { get; set; } public override string tostring() { return string.format("{0}, {1}", latitude, longitude); } }
Comments
Post a Comment