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

倖福魔咒の 提交于 2019-12-25 17:59:27

问题


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


回答1:


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!



来源:https://stackoverflow.com/questions/39814117/google-maps-apis-to-return-place-type-based-on-latitude-longitude

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!