Google maps APIs to return place' type based on latitude & longitude - google-maps

I am trying to build an application in which I need to retrieve location's type based on latitude and longitude. I tried using google's places API but not getting satisfied results.
For eg, if I want to know if the user searches for SFSU, it should be stored as 'university'. I can get its latitude/longitude from geocoding APIs.
https://maps.googleapis.com/maps/api/geocode/json?address=SFSU&key=YOUR_KEY
But from places API, I cannot get the exact type, I mostly get it as street or establishment:
https://maps.googleapis.com/maps/api/geocode/json?latlng=37.7244047,-122.4760196&key=YOUR_KEY
Similarly, I wanted to get cafe for any starbucks or mall/shopping-center for any mall.
Edit:
I got confused between geocode API and places API as geocode API also returns place' type.
I found that places API returns multiple results even if we provide correct latitude and longitude. So if we need the perfect result, we need to provide sort filter with Places API.
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=(lat),(long)&rankby=distance&key=YOUR_API_KEY

It looks like you are using reverse geocoding, not the Places API.
Request to Places API should be something like:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.7244047%2C-122.4760196&radius=10&type=university&key=YOUR_API_KEY
This one returns 'San Francisco State University, 1600 Holloway Avenue, San Francisco'
https://developers.google.com/places/web-service/search#PlaceSearchRequests
Hope it helps!

Related

How to find municipality and postal code that are in range from coordinates?

Is there a way by using azure-maps or google-maps to get from longitude and latitude all postal codes and municipalityes that are in range of X kilometers?
I've yet checked the Get Search Nearby of azure, but it returns only points of interests and it is not possible to specify in the API a range in which the data should be get.
In Azure Maps, getting all postal code/municipalities within a specified distance of a location or within an area is not currently available. However, this is something being investigated as a possible future service. Consider submitting this as a feature request here: https://feedback.azure.com/forums/909172-azure-maps
I don't believe Google Maps has any such service either.

Return data between geocoding api and google map is diffrent

I use geocoding api check the address,but sometime it does not works.
A place I can find it in google maps, such as,
https://www.google.com/maps?f=q&source=s_q&hl=en&geocode&q=United+States+Florida++33016+Hialeah+Gardens+8038+NW+103rd+St,Unit+39+Miami+Cores++
but it returns 'ZERO_RESULTS' when I use geocoding api to check the address,
https://maps.googleapis.com/maps/api/geocode/json?address=United+States+Florida++33016+Hialeah+Gardens+8038+NW+103rd+St,Unit+39+Miami+Cores++&sensor=true
{
"results" : [],
"status" : "ZERO_RESULTS"
}
Maybe the data between google map and geocoding api is diffrent.
Or I use the geocoding api in a wrong way,format the address?
You try to find business Miami Cores Inc using Geocoding API.
Please note that Geocoding API works only with street addresses, all business results are out of the scope.
In case when your intention is to search a business, Places API is the best option.
E.g.
https://maps.googleapis.com/maps/api/place/textsearch/json?query=8038%20NW%20103rd%20St%2C%20Hialeah%20Gardens%2C%20FL%2033016&key=YOUR_API_KEY
This should work now, since Issue 10585 has been fixed:
Query: United States Florida 33016 Hialeah Gardens 8038 NW 103rd St, Unit 39 Miami Cores
Result: 8038 NW 103rd St, Hialeah Gardens, FL 33016, USA (source, API request)
The Geocoding API will find the same result as Google Maps, but return only the address of the place. If you need business names, phone numbers, etc. you'll need to use the Places API (Autocomplete or Search) instead.
However, I wouldn't count on Google Maps APIs to always understand your backwards query, your query terms are in the reverse than usual order. You may want to adhere to the following to get better results:
How should I format my geocoder queries to maximise the number of successful requests?
Best Practices When Geocoding Addresses

Why do I get different result from geocode api vs google maps

I am new to google geocode API but I am planning to use the free version to get map coordinates for nearby golf courses. I started with my home course:
http://maps.google.com/maps/api/geocode/json?address=Karlstad+golfklubb
Plus "&key=[my generated api key]"
I get a result with status="OK" but the resulting long/lat is not correct. It's near but misses with 7-8km.
When I use maps.google I get correct location. Searched for "Karlstad golfklubb".
https://www.google.se/maps/place/Karlstad+Golfklubb/#59.4346545,13.5140563,17z/data=!3m1!4b1!4m2!3m1!1s0x465cb41aca8c1467:0x64836d18f18df2f6
Why do I get different geo locations when using the same keywords. Do they operate on different databases or do I need to enter more params?
I also tried with other nearby courses like "sommarro" and "bryngfjorden" but for they I get zero result. But no problem finding them in google maps.
If you look at the JSON code, they describe the formatted_address as
"formatted_address" : "Karlstad Golfbanan Jako, 652 30 Karlstad, Sweden"
Which if you enter into Google Maps shows the correct longitude and latitude in the JSON.
https://www.google.com/maps/place/Karlstad+Golfbanan+Jako,+Sweden/#59.3602394,13.472185,17z/data=!3m1!4b1!4m2!3m1!1s0x465cb23bc0f46911:0x66ceae446bdc95dc

Google maps GeoCode API doesn't return any result at all?

This is weird. When I search something like "The New York Palace Hotel,America,New York" in Google maps app's search box I get exactly the hotel on the map.
However When I use the maps API,
A GET at http://maps.googleapis.com/maps/api/geocode/json?address=The%20New%20York%20Palace%20Hotel,America,New%20York&sensor=true
I get ZERO results in the response.
It doesn't even give New York as the option in search results.
I am making an app where I use this API to get the lat-long for user provided address.
Now, I don't know why this Google maps API doesn't work the way the Google maps app works.
BUT I wanted to know, is there a way to search and provide Google maps API these search terms as meaningful words where instead of taking whole string as one parameter it knows which city I am searching and which Address I ams searching.
If not, then only option left with me will be to Once the first results fails I make another query for city name only.
recently, i was given a similar task, and came to know the api works reverse... i.e.. we can get address for lat lon that we provide.. and that too has its own restrictions (i.e.. no.of addresses resolved per request, mostly some 2500 address per day something...)....here you can get some info over that...
You are using the Geocoding API. "The New York Palace Hotel,America,New York" is not an address, it is a "place". The Places API might be a better option.
Example of your query using the (javascript version of) the Places API

How to look up ZIP/Postal Code by City using Google Maps API?

How can I extract a Postal Code or ZIP of a place by giving Google Maps a city on the map?
Basically I'm looking for a free verification service for checking completed addresses for accurate details.
I seem to remember the maps API can somehow provide a geographical point when given an address. Now I'm searching for a slightly reversed situation in order to validate the postal code typed in with a city.
You need to Geocode the address to get best match coordinates
and then Reverse Geocode the coordinates to compare zip.