Trying to get the state from maps.googleapis.com/maps/api/geocode/xml is not working for me because not all results are in the same order
The problem is not all locations are the same, I'm using coordinates as the parameter in the urls, most are address_component[5], but the others put the state any and ever where else. The only thing that seems consistant is the formatted address.
See these 2 examples, the states are in different order
for one $xml->result->address_component[5]->short_name is the state
for the other $xml->result->address_component[4]->short_name is the state
https://maps.googleapis.com/maps/api/geocode/xml?latlng=38.7811981,-75.6823615&sensor=false
http://maps.googleapis.com/maps/api/geocode/xml?latlng=36.370791599999996,%20-76.75601170000002&sensor=false
There has to be a simple answer! Thanks
Related
We use the Google Maps API, and when a user inputs a 5 digit ZIP code, the results are correct the vast majority of the time; it treats the input as a ZIP code and returns results based on that location.
The problem that has come to our attention is that queries for certain ZIP codes (42025 is our prime example) does NOT return the expected results (Benton, KY). The API call actually returns "status":"ZERO_RESULTS". A similar search on maps.google.com will sometimes produce a positive result, but only if Benton, KY consumes a large portion of the viewport already. A workaround is to add the term "zip" in the query string.
My investigation has shown that the failed results appear to be using the 5 digit string as if a street address, which find nothing. A query for "42020" ends up showing some address near Washington D.C., for example.
Has anyone faced this issue? Any suggestions for how to address this?
I would suggest using a component filtering in your Geocoder requests in order to obtain postal codes.
Your requests will be rewritten as
https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A42025%7Ccountry%3AUS&key=YOUR_API_KEY
https://maps.googleapis.com/maps/api/geocode/json?components=postal_code%3A42020%7Ccountry%3AUS&key=YOUR_API_KEY
Both requests return expected results to me. You can also see it in the Geocoder tool:
https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/utils/geocoder/#q%3D%26options%3Dtrue%26in_country%3DUS%26in_postal_code%3D42025
https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/utils/geocoder/#q%3D%26options%3Dtrue%26in_country%3DUS%26in_postal_code%3D42020
I hope this helps!
This worked for me. Only with zip code search.
verifyZipCode_google(zipcode) {
return this.httpClient.get(`https://maps.googleapis.com/maps/api/geocode/json?address=${zipcode}&components=postal_code:${zipcode}®ion=us&sensor=true&key=${environment.GOOGLE_API_KEY}`);
}
I need to Geocode all the branches of a chain within a country or state currently I am able to fetch a single result but I need to get the data for all the branches.
https://maps.googleapis.com/maps/api/geocode/json?address=macdonaldsIndia&key="MY-API-Key"
I think I am missing some extra parameters that need to be passed in the api.Please suggest if I am missing something
Thanks in advance
You should look into Places API web service. With nearby search or text search you can get up to 60 results.
For example if I search 'macdonalds India' for location 28.661898,77.227396 with radius 50km I can get 22 results. 20 results in the first page and 2 results in second page that I get using page token parameter.
https://maps.googleapis.com/maps/api/place/textsearch/json?query=macdonalds%20India&location=28.661898%2C77.227396&radius=50000&key=YOUR_API_KEY
https://maps.googleapis.com/maps/api/place/textsearch/json?pagetoken=CpQCDwEAANFmh2yBVwmsgsOuEDlbKLLHXYhkn7WZNsstXOHBatJm_Js2MwEPSwHb16ICXzdt5PYu37NYPTr17MBdM6c0fIqjlB7V5otC-55bjde7Ns3l9igjMvu_hePMn03WXiRaeT7PQ8eoVTNAJQu0OrINTFtNNtU7xCm1p6UIGAzMm_phr_ZL955wTTPtqWq3XadfsdAgkwdrl2lQEbbYXhikwo-SrSfKoH2scOYrdJQ4y3SaPx95BKLPjAz8D_RfncXzQ4jVJeamuITQXMAjr1DbzKPFFNiCP3Yq_Ps7iUiUZRW8cSi5XB9RGjQN8zCQCTKWYwTWCdwfz8f49dKmj8GLw0mMfLwjJaE9tNaT1ZiEB8FMEhAD9pDF_U4CbEN8qFcgEJWFGhQ0qCZwK5EHNlVqGqk9hCYpHw9p0Q&key=YOUR_API_KEY
Visually it looks like
Hope this helps!
Putting it simply, we have some Norwegian postcodes and are using the API to get their addresses and lat & long. Nothing to highbrow, but on around 10% of the postcodes. The API returns no results, here's an example:
Success for postal_code=1151:
http://maps.googleapis.com/maps/api/geocode/json?components=country:NO%7Cpostal_code:1151&sensor=false
Fail for postal_code=2066:
http://maps.googleapis.com/maps/api/geocode/json?components=country:NO%7Cpostal_code:2066&sensor=false
I have noticed that the majority appear to be for the Postboks (presuming equivalent of PO boxes in the UK).
However, it's not true for all of them.
Has anyone similar experience and or perhaps a better knowledge of Norwegian postcodes?
Thanks
I tried your given request, and I found that postal_code=2066 give you ZERO_RESULTS, If you are looking to the name Jessheim, am I right? Then I think you should use the postal_code=2069, this will give you the request that you want.
Here is the request that I used.
maps.googleapis.com/maps/api/geocode/json?components=country:NO|postal_code:2069&sensor=false
Also, I think you should know first the correct/available postal code that you used. I tried to request generally in which I did not set any country as a filter.
First, I used the postal_code=1151, and as you can see, you will find the 1151 Oslo, Norway address in the result. Which means the postal_code 1151 is available in Norway.
maps.googleapis.com/maps/api/geocode/json?components=country:|postal_code:1151
Second, I used the postal_code=2066, and you will not find any address that the country is NORWAY.
maps.googleapis.com/maps/api/geocode/json?components=country:|postal_code:2066
For additional note, if you use two components value in your request.
You need to use pipe(|) to separate them. I hope I help you with this
:)
KENDi - thanks a lot for your help and answer. I found out that Norway has two types of postcode. One is for the street addresses, the other is for postboxes (or PO Boxes in the UK) that don't have an geographical address.
Here's an example
http://adressesok.posten.no/en/postal_codes/search?utf8=%E2%9C%93&q=Molde
I have use the code given below, please copy and paste in your URL, which gives latitude and longitude of a specific place.
But when I have used the same call with wrong place it returns latitude and longitude. How to check whether it is right and wrong?
http://maps.google.com/maps/api/geocode/json?address=dubai+United+Arab+Emirates&sensor=false
http://maps.google.com/maps/api/geocode/json?address=anu+India&sensor=false
Thanks
A typical scenario for using geocoding will be when you know that the address exists and you want to get the location coordinates, maybe to mark on a map. When you search an address in google geocoding api, it will find exact matches and also partial matches to correct for cases like spelling mistakes or multiple spellings in use. Due to partial match, when you search for a word, words close to that in terms of the letters used and the number of letters present will also be found. You can explore 2 options to refine the results:
1, If you want to avoid partial matches , you can try component filtering , where you specify filters on components like locality, country , etc and only exact matches will be returned.
2, You can process the json result in your code by retreiving different components and doing comparisons and taking only cases matching your requirement.
I'm getting really frustrated with Google geo results and hope someone can advise me the best was to go.
I have created a AutoSuggest feature where you can start typing the address and Google will respond with suggestions. User then selects and address to move on.
But before I want them to continue on the next page I want to validate their selection. I would have thought this will be easy as we are only checking against what Google has already given. But when I do my validation lookup it displays no results.
Some example code:
Lets say I picked from the suggestion this address: Suffield, CT 06078, USA
Then on validation I do a second lookup with this address ie.
$string = "Suffield, CT 06078, USA";
echo 'http://maps.google.com/maps/geo?output=json&oe=utf8&gl=us&sensor=false&key=[MyKey]&q='.urlencode($string).'';
It gives me Error code 602 (G_GEO_UNKNOWN_ADDRESS)
How can it not be found when its given me the address?
How I can get around this?
You're right. That is quite strange.
Note that it does work when you remove the space between CT and 06078:
http://maps.google.com/maps/geo?q=Suffield,+CT06078,+USA&output=csv&sensor=false
The above returns 41.9817631,-72.6506462. (Link to Google Maps)
Reverse geocoding those coordinates with:
http://maps.google.com/maps/geo?q=41.9817631,-72.6506462&output=csv&sensor=false
returns:
200,4,"Suffield, CT, USA"
It's really strange, to be sure, but I was able to validate the address using the full state name.
Doesn't work:
http://maps.google.com/maps/geo?output=json&oe=utf8&gl=us&sensor=false&key=[MyKey]&q=Suffield,%20CT%2006078
Does Work:
http://maps.google.com/maps/geo?output=json&oe=utf8&gl=us&sensor=false&key=[MyKey]&q=Suffield,%20Connecticut%2006078
And yes, the address they provided to you doesn't work in their own system. That being said, searching for Hartford, CT DOES work. It appears there may be a listing discrepency in their data whereby Suffield + CT returns false results.