开发者

Correct address format to get the most accurate results from google GeoCoding API

Is there any standard format to supply the address str开发者_如何学运维ing 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


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.


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


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.


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);
  }
});


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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜