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

后端 未结 4 1491
日久生厌
日久生厌 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 09:46

    You also can use direct search instead of nearbysearch https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY

    Look at Getting Started with Geocoding

    0 讨论(0)
  • 2020-12-30 09:52

    Look at this docs. You will get the lat,long,name for the Address and then call this below google api

    https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=YOUR_API_KEY
    

    You will get a response like this

    {
      "html_attributions" : [],
      "results" : [
        {
          "geometry" : {
            "location" : {
              "lat" : -33.870775,
              "lng" : 151.199025
            }
          },
          ...
          "place_id" : "ChIJrTLr-GyuEmsRBfy61i59si0",
          ...
        }
      ],
      "status" : "OK"
    }
    

    For there you will get the place-id.

    Note: Please enable the GeoLocation Api from Google Developer Console otherwise it return the error msg :This API project is not authorized to use this API.

    0 讨论(0)
  • 2020-12-30 09:53

    Both of the proposed ways cost money and I think peoples should mention it. We have the -$200 from the Google, but its all depends from how much users you have and how frequent you need to use the geocode. 60k requests per month to the geocoder - easy $300 only for to use the geocode https API :

    Nov 1 – 30, 2018 Geocoding API Geocoding: 6073 Counts - $30.38

    Dont filter what you need in the responses, like we have in the requests from other posts? Expect way more:

    Nov 1 – 30, 2018 Places API Places Details: 2389 Counts $40.61

    Nov 1 – 30, 2018 Places API Contact Data: 2385 Counts $7.17

    Nov 1 – 30, 2018 Places API Atmosphere Data: 2385 Counts $11.95

    0 讨论(0)
  • 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<PlaceLikelihoodBufferResponse>{
        override fun onComplete(p0: Task<PlaceLikelihoodBufferResponse>) {
            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

    0 讨论(0)
提交回复
热议问题