Google Location API vs. Maps: Why are identical queries yielding different results? - google-maps

I'm losing some hair over Google's AJAX API currently. What I do is turning structured location data into a Google local search API query in order to give users an alternative result list of places.
ex.:
http://ajax.googleapis.com/ajax/services/search/local?v=1.0&key=XXX&hl=en_US&mrt=localonly&rsz=large&q=pizza+Neustadt+DE
However, the API behaves very oddly at times, often not taking into account certain parameters I pass to it. For instance:
If I search for "term Rome Roma IT" on Google Maps, then it finds all terms in Rome as expected. If I repeat the same search on the API, I get zero results (I have to remove either 'Roma' or 'Rome' for it to work -- Roma is the administrative region here, and Rome the city name).
Why is that?
Another example. There is like 20 different towns, cities and boroughs called Neustadt in Germany. Now, when I search on Google Maps, it only finds one, unless I specify an additional qualifier, like a region or something.
Now, on the API level I kinda expected that when passing lat/lon parameters along with a query for Neustadt then it would be clever enough to pick the correct Neustadt by looking at the geo coding. But that doesn't happen, it always picks the same Neustadt and ignores the geo data.
q=pizza+Neustadt+DE&sll=48.8053,11.7579
I had similar problems when doing bounding box searches. The bounding box seems to be ignored completely, since I'm still getting result data which is a hundred kilometers off:
q=pizza+Neustadt+DE&sll=48.8053,11.7579&sspn=0.00001,0.00001
The last result is not even in the same city; shouldn't the tiny bounding box not result in any data whatsoever? I could even pass a zero size BBox and I would still get results.
I know there's an actually quite extensive documentation for the Local Search API, but it never goes into detail about which parameters are used when and how a query has to be structured and is evaluated, which makes it very difficult to get decent results.
Do you have any hints, tipps, suggestions on how to get to grips with Google Local search?
UPDATE:
I just found something REALLY odd. Could someone please go to this website:
http://code.google.com/apis/ajaxsearch/documentation/localsearch/index.html
open firebug, and monitor the HTTP traffic when typing in this search query:
test Rome Roma IT
You will get a bunch of results on the map. Now copy the URL that was contacted via AJAX and send a request to it on the command line:
curl "http://www.google.com/uds/GlocalSearch?key=internal-sample&v=1.0&rsz=large&sll=41.97684819454683%2C12.486648559570312&sspn=0.204185%2C0.549316&q=test%20Rome%20Roma%20IT&lssrc=lsc&lscstyle=final&start=0&callback=_callbacks_._5g139yfuc"
Now I get ZERO results. How can that possibly be? It's definitely not the key or callback args, I removed them without any change to the outcome of that query.
Is Google extending their search results when a query comes from one of their servers?

I've encountered exactly this same problem and it seems to be down to a combination of licensing issues and the fact that what Google exposes via its APIs and what it displays in the Maps/Google search pages are a combination of different searches (search, maps, base, data etc.etc.)
On the licensing issue, it seems that Google can display more information when a user goes via the browser, compared to requests via API calls (which could theoretically be automated).
See here for example.

Related

Google Places API - Nearby Search not as accurate as Maps?

Overall goal: map a list of completely unknown GPS coordinates to closest points of interests (I dont know if the coordinates are referring to a shop, mountain, museum etc.).
The Google Place API, exactly the Nearby Search (https://developers.google.com/places/web-service/search?hl=de#PlaceSearchRequests), is theoretically solving my problem: I can pass GPS coordinates and a radius and get a list of "places" back.
Unfortunately, the results are not really precise. However if I "google" the very same coordinates in Maps, I get very satisfying results.
Examples:
48.12429, 11.56774:
Maps shows shop "Kenneth Kobonpue" really close by;
API call with radius 10/50/100 does not mention this shop at all
48.15100, 11.57964:
Maps shows University of Munich;
API call with radius 10/50/100 just mentions some special university rooms
48.16404, 11.60370:
Maps shows "English Garden" (park in Munich);
API call with radius 10/50/100 does not mention this park once
etc.
Question: Is there an option to get better results using this API? Is there another (Google) API more suitable to my usecase?
Google Maps(maps.google.com) and Google Maps Platform APIs are two different products and will behave differently at times. Their features, results and behaviors are not expected to be always the same.
In general, Places API requests returns the prominent places depending on the parameters you have provided. It is possible that the place you are looking for is not a prominent point-of-interest given the distance from your location.
Taking your sample for the location, "48.16404, 11.60370", you'll get the expected "English Garden" in a distance of 500. Here's a sample request: https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=48.16404%2C%2011.60370&radius=500&key=YOUR_API_KEY
Another alternative is to use the "rankby" parameter and set it to "distance". This will bias the results according to their distance from the given location. However, you need to specify one or more of the following parameters: keyword, name, or type (required parameters if results are rank by distance). Here's another example: https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=48.16404%2C%2011.60370&keyword=garden&rankby=distance&key=YOUR_API_KEY
In addition, by default, each Nearby Search returns up to 20 establishment results per query only. However, each search can return as many as 60 results, split across three pages. It is also possible that the point of interest you are looking for is in the succeeding pages. You can use the next_page_token parameter in another search request to access additional results.
For more information regarding Places Nearby search, you can checkout this link: https://developers.google.com/places/web-service/search#PlaceSearchRequests
This seems to be a recent bug, I am pretty sure I saw thsi working before.
Maps search shows very different set of places vs
using the APi, regardless of ranking parameter https://maps.googleapis.com/maps/api/place/nearbysearch/json?keyword=grocery&radius=5000&location=51.5183332%2C-0.2752538&key=[YOUR_KEY_HERE]
In this case, it is very clear that the platform API returns incorrect results using a different center point than the parameter provided.

Google Places API Text Search doesn't filter address correctly

I am using Google Places API Text Search to fetch for pharmacies and looks like it isn't filtering address correctly.
When I search for Walgreens, it returns some results from Broadlands, Herndon and some other locations.
If I search for Walgreens Broadlands or Walgreens Herndon, it returns nothing.
But if I search for Walgreens Miami or Walgreens Village it returns correctly.
Other strange behaviour is that, sometimes, executing the same request two times returns different results. For that reason, I don't know if you will get the same results using the links I provided.
Google documentations states the following:
The service is especially useful for making ambiguous address queries in an automated system, and non-address components of the string may match businesses as well as addresses. Examples of ambiguous address queries are incomplete addresses, poorly formatted addresses, or a request that includes non-address components such as business names.
From my understanding, the examples I gave should work just fine.
Am I missing something? What is wrong in these cases?
It sounds like a bug, I would suggest filing an issue in Google Issue tracker for Places API.
The unique workaround I can think about is providing an additional information about the area where you are searching the Walgreens pharmacy. I believe the queries with location bias work better than without it. If I use the coordinate of Broadlands (39.0181644,-77.5202688) and specify radius of 50 km, the Places API text search for Walgreens return results
https://maps.googleapis.com/maps/api/place/textsearch/json?query=walgreens&location=39.0181644%2C-77.5202688&radius=50000&type=pharmacy&region=US&key=MY_API_KEY
as shown in the screenshot
I hope this helps!

Locating current Google Place i'm at by latitude/longitude via Google Places API

i have a lat/long location data and i need to get current Google Place where i'm at now.
For example, if i'm in a shop(cafe, gym, etc..), i need to get info about THAT particular shop(cafe, gym, etc..).Or at least the closest one.
So, i'm doing it this way:
First i fetch place basic info(placeid,name, etc.) via Google Places API Nearby Search request:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=40.7597351,-73.9836576&radius=16.66&key=...
Then i find the closest one(which is apparently where i am) and perform Place Details request with it's placeid
So, everything works fine, except for some places like the one located at 40.7597351,-73.983657 (New York Guitar lab shop) which i can see on google map, but can't get in my response. Even places that are further from my location than this, are being found fine.
I've already tried to use rankBy=distance and then checking if the result is in required radius manually, still no use. Actually, maybe this approach is right, but as told in the docs, it's required to use types parameter with rankBy=distance. So, i set types=establishment since i actually need everything except addresses and locality tokens returned. I think that the problem is some places i need, are neither counted as establishments nor as localities, but i don't know the optimal way to exclude
all types specified at (https://developers.google.com/places/documentation/supported_types) Table 2 from my response. Is there a way to get only places which types are in Table 1 (except for specifying them ALL in my types param, haha)
So, could you please help me with how can i do this?
Thanks:)
P.S. here is very similar but unaswered question
Google Places API Displaying Inaccurate Result
It seems that there's explanation here (https://developers.google.com/places/faq#why_are_some_places_never_returned_even_though_they_have_google_pages). Looks like some places are just not yet verified by Google.
And yes, the establishment is the generic category for all non-localities. So you can be sure that if you set type=establishment then you'll have as much places as you will, if you'll specify all types from Table 2. Good Luck!

Getting correct address from user typed street address using google maps

I've never used the google-maps api, but I just want to do one particular thing.
I've got around 1000 user typed street addresses. Some are missing states and postcodes. I've noticed if I type these addresses into google maps it generally gives me back the state and postcode (only very rarely it gives some options). Is there a way to do this programatically, so I don't have to manually copy/paste this in? Has someone already made an application/library to do this that I can just feed the user typed data to?
Edit:
I've noticed this does the job:
https://maps.google.com.au/maps?q=1%20George%20st%20sydney
It returns state and postcode. But it returns it on a webpage with a whole lot of other stuff. I just want the address only. I guess I could grep through the results, but some additional thing to add to the query string so it only returns the raw address (or some structure) would be useful.
You can use the Geocoding API - https://developers.google.com/maps/documentation/geocoding/
E.g. http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=1%20George%20st%20sydney ; you can replace "json" with "xml" if you prefer. Look for "formatted_address" in the result, or individual address components, depending on what you need.
However, I'm quite frustrated that it sometimes doesn't work, even for some cases where the regular google maps search is successful.

Dynamically increase Google Map v3 search area when no results returned to include at least 1?

I followed this example and successfully built a store locator:
http://gmaps-samples-v3.googlecode.com/svn/trunk/localsearch/places.html
My problem is that some searches do not return any results when the search location is not near a well populated area. To see what I mean you can load the example URL above and try either search below which combines the "T-Mobile" Keyword with the zip for either Death Valley, CA or Yosemite Valley, CA:
T-Mobile 92328
T-Mobile 95389
The Google API is not sending any results for either of these ZIP codes. (Makes sense since there are probably no T-Mobile stores within a great distance)
I need to find a way to handle this and did extensive research but found nothing. Is there a way to either:
Widen the search area if the Google API does not return a result to include at least 1 result.
Start with a wider search area to minimize the occurrences of no T-Mobile stores being found within a given area?
Thanks for your time!