kuemme01 kuemme01 - 4 months ago 21
Android Question

Easy and fast way to get places by query in googleMaps API

I'm just doing a rebuild of my iOS App in Android, here and there horrible to do. One horrible part is that map thing.

I need to get places around users location by query like

"park", "cafe", "bakery"
In swift I just used

self.localSearchRequest = MKLocalSearchRequest()
self.localSearchRequest.naturalLanguageQuery = mapSearchQuery
self.localSearchRequest.region = region
self.localSearch = MKLocalSearch(request: self.localSearchRequest)

for item in localSearchResponse!.mapItems
let annotation = MKPointAnnotation()
annotation.coordinate = item.placemark.coordinate
annotation.title = item.name

Is there a similar way to do the same in Android by using GoogleMaps API? The only way I found was to get them via JSON from https://developers.google.com/places/web-service/search and I'm not even sure if this is for Android applications.

The GooglePlaces API for Android just list all places around a location without a way to filter them or something.


after long trying I was going with the following solution. Using the GooglePlaces webservice (link in my question):

final String PLACES_API_BASE_URL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?";
    final String LOCATION_PARAM = "location";
    final String RADIUS_PARAM = "radius";
    final String KEYWORD_PARAM = "keyword";
    final String LANGUAGE_PARAM = "language";
    final String KEY_PARAM = "key";

    mDestinationUri = Uri.parse(PLACES_API_BASE_URL).buildUpon()
            .appendQueryParameter(LOCATION_PARAM, String.valueOf(latitude)+","+String.valueOf(longitude))
            .appendQueryParameter(RADIUS_PARAM, "1000")
            .appendQueryParameter(KEYWORD_PARAM, naturalLanguageQuery)
            .appendQueryParameter(KEY_PARAM, "YOUR_API_KEY")

If this will accept from google we will see.