26

Is there any standard format to supply the address string to Google GeoCoding API to get the most accurate results on map.

For Eg. following query not giving correct result.

http://maps.googleapis.com/maps/api/geocode/xml?address=bloom,Bloomfield,CT,06002,USA&sensor=false

Thanks

Mandeep

mandeep-dhiman
  • 2,505
  • 2
  • 21
  • 31

6 Answers6

34

I believe the suggested format is:

House Number, Street Direction, Street Name, Street Suffix, City, State, Zip, Country

The results get less specific the less information you can supply, obviously.

In your sample, the geocoder is searching for a street named 'bloom', of which there are similar matches in OH instead of CT. Removing 'bloom' from the query and then searching returns Bloomfield, CT.

Casey
  • 2,025
  • 3
  • 20
  • 22
  • 3
    Google doesn't say the right format, but **** it, this works! :) – Mauricio A. Cinelli Jan 28 '14 at 13:22
  • I have serious doubts that this works very well! country and zip should go first IMHO! – cs0815 Mar 09 '15 at 19:51
  • @ftrotter are commas necessary to get better results? – mfaani Sep 01 '16 at 06:42
  • I have not tested that, I just assume that they have an advantage when they can use them as a delimiter. I suspect an answer that details the differences between "with comma" and "without comma" would be better than mine, and I would upvote it as such.. – ftrotter Oct 18 '16 at 02:43
5

Definition of Google address search:

address - The street address that you want to geocode, in the format used by the national postal service of the country concerned. Additional address elements such as business names and unit, suite or floor numbers should be avoided.

https://developers.google.com/maps/documentation/geocoding/#geocoding

How should I format my geocoder queries to maximise the number of successful requests?

The geocoder is designed to map street addresses to geographical coordinates. We therefore recommend that you format geocoder requests in accordance with the following guidelines to maximise the likelihood of a successful query:

  • Specify addresses in accordance with the format used by the national postal service of the country concerned.
  • Do not specify additional address elements such as business names, unit numbers, floor numbers, or suite numbers that are not included in the address as defined by the postal service of the country concerned.
  • Use the street number of a premise in preference to the building name where possible.
  • Use street number addressing in preference to specifying cross streets where possible.
  • Do not provide 'hints' such as nearby landmarks.

https://developers.google.com/maps/faq#geocoder_queryformat

phlegx
  • 2,618
  • 3
  • 35
  • 39
3

I found the answer incomplete and it lacked a source.

Look here: https://developers.google.com/places/documentation/autocomplete#place_autocomplete_responses

The maps autocompletion API from google returns a much simpler format: "Street address, City, Country" Now you can use a string like that to search for an address and it should lead to one exact result. In addition if you use the autocompletion API you will get a unique identifier too which can be used for further detail requests.

The format of the street address greatly depends on the location where you actually are. In the US "House number, street direction, street name, street suffix" might make sense, in most of Europe it will not lead to successful query.

Addresses in most of EU are different (often "Streetname number suffix") like "Kumpelstraat 25A","Psolevcu 331/26b") and I guess we'd be surprised if we look at some eastern countries.

So if you bind your code to a single area (US, most of EU) you might be good hardcoding the format.
If you want to have a more flexible system you either need to find out propper formating for your target audience or query one of googles APIs to automatically get a proper string. The one I linked is very good but requires an API key with a free request limit per day.

John
  • 7,507
  • 3
  • 52
  • 52
  • I should add, I use this method successfully in an android APP. Seems to work well. – John Apr 15 '14 at 23:05
3

I stumbled upon this question and found a solution that worked for me:

I think the answer can be found by using component filtering, look at: https://developers.google.com/maps/documentation/geocoding/#ComponentFiltering

An example in Javascript:

var request = require('request');

var url = "https://maps.googleapis.com/maps/api/geocode/json?" +
    "address=Herengracht 180" +
    "&components=postal_code:1016 BR|country:NL" +
    "&sensor=false";

request(url, function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
  }
  else {
    console.log('error', error);
  }
});
Whyhankee
  • 822
  • 10
  • 14
  • 1
    One caveat to using component filters is that a query containing a component filter will only return the geocoding results that match the filter. If no matches are found, the geocoder will return a result that matches the filter itself. If you are want ZERO_RESULTS when a geo-code fails, you will probably not want to use component filters. – Scott Nov 04 '15 at 22:05
1

No need to avoid apartment units. This works:

https://maps.googleapis.com/maps/api/geocode/xml?address=14202+N+42nd+St+Unit+301+33613

"Apt", "Room", and "Suite" work as well

They all return 301 as subpremise and are shown in "formatted_address" as "#301."

Paul sends...

Paul Kranz
  • 11
  • 1
0

I found that official country codes like "US", "DE", "FR" do not work well. Replacing them with the full country name gives much better results for me.

I did not find a source where that is stated.