How to get the best matched result with The Google Geocoding API - google-maps

there is any way to get a single, best matched element from this url:
http://maps.google.com/maps/api/geocode/json?address=Lipinki&sensor=false&components=country:PL
I have to get a single element for results for Poland. I would to get the same result which i can see on maps.google.com.

Unfortunately there is no way to do it. Google will send you a list of possible matches and you have to use it. Generally first one is the closest one but no guarantees there. Best way is to show multiple spots on map or just use the first one. If you want exact match your address=Lipinki should contain full address (street address).
Regarding your second question, yes you will get same location you see in google maps search. Look at the geo points they are pretty close.

Related

Google Places API turn locationbias off

I have the following request url:
https://maps.googleapis.com/maps/api/place/textsearch/json?input=London&inputtype=textquery&type=pet_store&key=API_KEY
I am trying to disable locationbias but have no luck. I tried adding &locationbias=point:lat,long to my request but the results are still biased to the location of the IP address
I also tried adding location=0,0 and radius=1 parameters as suggested in another thread.
Can someone point me in the right direction?
The Text Search service does not have a locationbias parameter, nor input for that matter; only the Find Place service does. If you're actually using Find Place, then note that this service only gives you 1 result/place per query, and since you're querying a city (London) then whatever value you set to locationbias won't really matter. In any case, locationbias cannot be "turned off". If you do not specify it, results will always be IP biased by default.
Based on your query, it seems that what you're trying to do is to get multiple places (pet stores) within London. You should use Text Search (or better, Nearby Search) for such use case. And if you wish to bias results to a specific region, then you can use the location and radius parameters as follows:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=123+main+street&location=42.3675294,-71.186966&radius=10000&key=YOUR_API_KEY
Nearby Search example:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=1500&type=restaurant&keyword=cruise&key=YOUR_API_KEY

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.

get all possible directions from A to B

I want to find all possible routes from point A to point B (not only shortest ones). So my question is, is there any web service api (because I use Java) for such request in Google Maps, Yahoo Maps etc. it doesn't matter which one..
I've found something about this topic in Google Maps Directions Api: "alternatives (optional), if set to true, specifies that the Directions service may provide more than one route alternative in the response. Note that providing route alternatives may increase the response time from the server." But unfortunately, I couldn't use this option, when I include alternatives=true inside request query I get the same result. That would be nice to have such an alternative - it's more flexible, but I found something guarantied one with waypoints (but its much like "hardcoding" - we specify streets that we will pass from). Anyone tried alternatives=true?!
Here's another approach and solution for this problem: convert meters to latitude longitude from any point
Thanks for your responses..
I'm using the fact that google maps' paths uses rounding boxes to get a circle, to do so i just choose the point that i want and create a route to another that is not the same but very very close to it, just like:
http://maps.googleapis.com/maps/api/staticmap?size=400x400&path=color:0x5600FF80|weight:100|51.5285582,0|51.5285583,0&sensor=false&zoom=15
We can choose the weight as the diameter of the circle, note that it is a fixed value, not related to the screen size and the zoom.

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

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.