How to get PlaceID from name, or lat, long in Android?

后端 未结 4 1514
日久生厌
日久生厌 2020-12-30 09:27

This my code:

Geocoder geocoder = new Geocoder(this, Locale.getDefault());
    List
addresses = geocoder.getFromLocationName(text, 10); te
4条回答
  •  [愿得一人]
    2020-12-30 10:07

    I do recommend to use get the Place Id like this. It would be better than call the API directly. I stumble for this issue all day. so I hope that it would be help. who're finding the way out to get place ID from your current location. for android

    Kotlin

    val mPlaceDetectionClient = Places.getPlaceDetectionClient(this.context!!)  
    val placeResult =  mPlaceDetectionClient.getCurrentPlace(null) 
    placeResult.addOnCompleteListener(object : OnCompleteListener{
        override fun onComplete(p0: Task) {
            val likelyPlaces = p0.result
            if(likelyPlaces.any()){
                // get the place ID from code below
                placeId = likelyPlaces[0].place.id  }
        }
    
    })
    

    or if who are implementing or developing on another language such a java. you can implement your code according to a reference below.

    java

    https://developers.google.com/places/android-sdk/googleapi-migration

提交回复
热议问题