简体   繁体   中英

Google Maps API, retrieving nearest places

I am making an app that requires the nearest supermarkets to be shown from a users current location.

I have seen similar questions to this asked and the answer vary widely. At the moment I am able to display a map at a specific location, with a marker above it.

What is the best way to find and display the nearest supermarkets?

I have read that reverse geocoding a position can give the address. But what is the best method of seeing all of the nearby addresses of the supermarkets? Can I connect using HTTP to a database that searches within a given radius from my position then use some sort of overlay to show them?

I have read numerous tutorials but most only show the very basics of showing the map......placing a marker of the current location....... then getting the lat/long position.

If anyone knows of any tutorials to show what I want to do above that would be great!

Google Places has a RESTful API that would suit your needs. Essentially, you would just pass in your lat & long position, a key corresponding to what you would like to find(gym, restaurants, etc) and the radius you would like to search.

You do have to sign up for an api key, but it is really easy. Here is the doc: https://developers.google.com/places/documentation/

do you have your own database of supermarkets to use? if so, and they are geocoded to lat/long when inserted, it should be trivial math to get those within a set radius, and use the basic examples for settings markers.

if you don't have your own database, you first need to pull the POIs from some webservice, and be subject to the quirks it may have.

You should have some kind of database of all supermarkets. If you don't you could for example use the Google Geocoding API , the Foursquare API or something else . Those records can either be stored in a HashMap or in a SQlite database.

Go through these locations and calculate the distance from the supermarkets to your users location (this can be done with lat/long distance ). This can be done from the client or the serverside (assuming you got your own server). After you got the distances to all supermarkets just pick the n nearest and display it on the map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM