GM42
GM42

Reputation: 1

Android, Kotlin, Google Maps Markers

I am trying develop an Android App with Kotlin in Android Studio. I want to make markers for Pharmacy in my app in Google Maps. My question is in my code:

private fun searchNearbyPharmacies(location: LatLng) {

    val placeFields = listOf(Place.Field.DISPLAY_NAME, Place.Field.LOCATION, Place.Field.TYPES)
    val request = FindCurrentPlaceRequest.newInstance(placeFields)

    placesClient.findCurrentPlace(request)
        .addOnSuccessListener { response ->
            for (placeLikelihood in response.placeLikelihoods) {
                val place = placeLikelihood.place
                val placeTypes = placeLikelihood.place.placeTypes
                placeTypes?.forEach { placeType ->
                    Log.i("PlaceType", "Place type: $placeType")
                }
                
                if (placeTypes?.contains(PlaceTypes.PHARMACY) == true) {
                    val latLng = place.location
                    latLng?.let {
                        addMarkerForPharmacy(latLng, place.displayName ?: "Pharmacy")
                    }
                }
            }
        }.addOnFailureListener { exception ->
            exception.printStackTrace()
        }
}

in the placeTypes there is no such thing as Pharmacy why is that? How can i fix it?

The code is working as if I change it from PlaceTypes.PHARMACY to PlaceTypes.MUSEUM in the following code

if (placeTypes?.contains(PlaceTypes.MUSEUM) == true) 

I can make markers for other type of places such as the Museum in this case.

Thanks in advance.

The code is fine as i can make markers like establishment, point_of_interest, museum etc. But there is no Pharmacy in there. But if i zoom in on the map I can see Pharmacys. I tried it in emulator and with real device also.

I write the placeTypes in the log and there are only these types:

placeTypes?.forEach { placeType ->Log.i("PlaceType", "Place type: $placeType")}

I  Place type: tourist_attraction
I  Place type: point_of_interest
I  Place type: establishment
I  Place type: street_address
I  Place type: transit_station
I  Place type: cafe
I  Place type: bar
I  Place type: restaurant
I  Place type: food
I  Place type: store
I  Place type: museum

Upvotes: 0

Views: 78

Answers (1)

kikoso
kikoso

Reputation: 708

In the version 4.0.0 of Google Places there is a Pharmacy type, you probably need to update your library version.

 public static final String PHARMACY = "pharmacy";

Upvotes: 1

Related Questions