Unable to restore street, city and country by reverse geocoding using google for Australian address

I have a requirement to get the street name, zip code, city, state, country, latitude, longitude from the given address.

It works great for Indian addresses, and when I tried the Australian address, it cannot get the street name and postal code. The rest of the things are great for extracting constraints from the address components that are in the JSON array.

I used the following code, which is mentioned in the Google Developers Forum

public void FrmGoogleGeoCode(string frmAddress) { string addUrl = "http://maps.google.com/maps/api/geocode/json?address='" + frmAddress + "'&sensor=false"; var result = new System.Net.WebClient().DownloadString(addUrl); GoogleGeoCodeResponse test = JsonConvert.DeserializeObject<GoogleGeoCodeResponse>(result); var response = test.results.First(); } 

As a result of var, I get a JSON array for the address components and the formatted address from the address components, I had a requirement to get the street name, city, state, zip code and country from the address of Australia.

Please open this question.

Thanks in advance

+4
source share
1 answer

Thanks for your reply, I tried the same address as 300 George Street, Sydney NSW 2000, Australia, but the answer is not an element in the address

 frmAddress ="300 George Street, Sydney NSW 2000, Australia"; 

This was my next code to retrieve the name of the street, city, suburb, country, zip code

  string addUrl = "http://maps.google.com/maps/api/geocode/json?address='" + frmAddress + "'&sensor=false"; var result = new System.Net.WebClient().DownloadString(addUrl); GoogleGeoCodeResponse test = JsonConvert.DeserializeObject<GoogleGeoCodeResponse>(result); var response = test.results.First(); string route=null; string locality=null; string pstlCode = null; for (int i = 0; i < response.address_components.Count(); i++) { int j = 0; var components = response.address_components[i]; string type = components.types[j].ToString(); if (type == "route") { route = response.address_components[i].long_name.ToString(); } if (type == "locality") { locality = response.address_components[i].long_name.ToString(); } if (type == "postal_code") { pstlCode = response.address_components[i].long_name.ToString(); } } frmLocation = route +","+locality +","+ pstlCode; 

then I tried George Street, Sydney, NSW, 2000, Australia with this code.

This was the next answer. Please, you can just send the code so that it helps me a lot.

 { "results" : [ {"address_components" : [ { "long_name" : "George Street", "short_name" : "George Street", "types" : [ "colloquial_area", "political" ] }, { "long_name" : "New South Wales", "short_name" : "NSW", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "Australia", "short_name" : "AU", "types" : [ "country", "political" ] } ], "formatted_address" : "George Street, NSW, Australia", "geometry" : { "bounds" : { "northeast" : { "lat" : -33.9134399, "lng" : 151.1667177 }, "southwest" : { "lat" : -34.0059442, "lng" : 151.0332033 } }, "location" : { "lat" : -33.9547504, "lng" : 151.1053691 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : -33.9134399, "lng" : 151.1667177 }, "southwest" : { "lat" : -34.0059442, "lng" : 151.0332033 } } }, "partial_match" : true, "types" : [ "colloquial_area", "political" ] } ], "status" : "OK" } 
+1
source

Source: https://habr.com/ru/post/1496514/


All Articles