Understanding the results of the Google Geocoding API

I use the Google geocoding API to process free-form address data and try to understand the results ( subpremise , administrative_area_level_2 , etc.). At the moment, I am only interested in addresses in the USA and would like to format the results as street address, city and state code. The status code seems simple ( administrative_area_level_1 ), but others are more vague. City of locality or sublocality or both or even more? The street address itself seems that it can be any number of combinations of other fields.

Ideally, I would just like to take formatted_address , remove the city, state, zip code and country code and save what remains as my โ€œaddress streetโ€. Are there any recommendations or recommendations for processing all of these fields, at least for most cases (regular addresses, addresses with unit numbers, etc.)?

+6
source share
5 answers
  • Street address street_number and route
  • City locality
  • State administrative_area_level_1
  • ZIP postal_code
  • Country country

Please note that Google ignores any device number (for example, "Apt 13A"). You will have to add this to yourself.

Running a sample of your data through a geocoder and manually checking the results should confirm that you get what you need.

+7
source

The documentation seems to cover what the various fields mean quite clearly.

You did not indicate what language you are working in, but I think this will help .

+1
source

I do reverse geocoding on Nearlots.com in the search pages. Basically, the user throws a marker somewhere on the map, and I type the address in the search box.

I just type 'formatted_address' and refuse if it is not there. It will give you something like this: "275-291 Bedford Avenue, Brooklyn, NY 11211, USA." This is more than enough - you can always cross out the USA at the end.

+1
source

I think you need to use the "route" for the street address.

I use the same service, and in my experience the โ€œrouteโ€ is always equivalent to the street address, even if this place is not a street!

I think you have already decided how to determine the name of the city. etc. This is the same approach that I take; take a look at the various API results for several different locations and see which field gives you the most consistent results.

0
source

After many hours of work on this, I was not able to consistently extract the apartment / room / under-premise. Having this part was more important than being able to specifically separate it, so I went around it using this.

 var componentForm = { locality: 'long_name', administrative_area_level_1: 'short_name', country: 'long_name', postal_code: 'short_name' }; function fillInAddress(place) { for (var component in componentForm) { document.getElementById(component).value = ''; document.getElementById(component).disabled = false; } for (var i = 0; i < place.address_components.length; i++) { var addressType = place.address_components[i].types[0]; if (componentForm[addressType]) { var val = place.address_components[i][componentForm[addressType]]; document.getElementById(addressType).value = val; } } var parts = $("#searchField").val().split(","); $("#street_number").val(parts[0]); } 

I extracted information from autocomplete as usual, although I missed street_number and route. Then he performed a simple auto-completion split after selecting and used the first portion, returning the address of the street as a whole (including factory / flat / room and street name).

This work has given me results that work well for what I need. Good luck

0
source

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


All Articles