Geocoder api returning single result - google-maps

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!

Related

Google Maps API query with only ZIP code provides incorrect results

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}&region=us&sensor=true&key=${environment.GOOGLE_API_KEY}`);
}

Google Maps Geocoding - Results in different order

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

Google Maps: Norwegian postcodes not returning any results

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

Drive API files.list query with 'not' parameter returns empty pages

I'm using the Drive API to list files from a collection which do not contain a certain string in their title.
My query looks something like this:
files().list(q="'xxxxx' in parents and not title contains 'toto'")
In my drive collection, I have 100 files, all contain the string "toto" in their title except for let's say 10 files.
I'm using pagination to retrieve the results 20 by 20, so I'm expecting to get only one page with the 10 files corresponding to my request. Surprisingly, the API returns 5 pages, with the first 4 having no results but with a nextToken page, and the files which are compliant with my request only come with the fifth page.
I'm still trying some use-cases here but it seems that it has something to do with the "not" operator. Like if the request was made without it, therefore returning 5 pages, but the results not corresponding to the request being removed from the response. It's very disturbing for me as I'm looking for the best performance here, and obviously having to make 5 requests to Drive instead of one single is not good for me. I'm also noticing that the results don't always come in the last page. I made the test with another collection, the results show up in the second page, but I still get 3 empty pages after that.
Am I missing something here ? Is this kind of behaviour "normal" ? I mean imagine if I had 1000 documents in my collection, having to make 50 requests to find only a few is not what I expect.
I have similar problem in files.list API. I tried to receive all three folders under root folder. I received result only on 342nd page. After several hours of researching I found some regularity in this strange behavior.
As I understood, the Drive API works in this way:
Detects something like index that best match your query
Selects first 20 records using index from step 1
Applies your filter: removes records that do not match your query
Rest is returned to you (maybe empty) with next page token.
The nextPageToken is looks like just OFFSET for the first record on next page in decided index, maybe it contains some information about query or index.
After base64 decode this token I found appropriate record number for next result in 121st position in decoded token.
Previously I built index of tokens using maxResults=1.
This is crazy, but I have no other explanation for observable behavior.
It is very useful for server because server do a very small work for search. From other side this algorithm must produce a lot of requests for pagenate whole list. But limitation for requests per second solve this problem.
Only You can do is pagenage and skip empty results. Do not forget about limitation of number of requests.
Do not try to find errors on your side. This is how Google Drive API works.
contains operator is working as a prefix matcher at the moment.title contains 'toto' will match "totolong" and "toto", but not "blahtoto".

how to check the google map api to know the place is existing one

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.