Google Places API Picker display Only Certain Types of Places

前端 未结 2 379
半阙折子戏
半阙折子戏 2021-01-04 00:17

I am making certain android app that requires user to choose a place. I am planning to user google places API.Link: https://developers.google.com/places/android/

Thi

相关标签:
2条回答
  • 2021-01-04 00:51

    This is still not possible (14 September 2015).

    Here is the open issue.

    (info copied from related post, and reverified)

    0 讨论(0)
  • 2021-01-04 01:06

    We are in 2017 and apparently this feature is still not implemented yet.

    Even so, you can check the type(s) of the selected place on the activityResult and use it. In my case, I wanted the app only accept Hospitals and related services, so here's the code:

     @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    //...
    boolean isAnHospital = false;
    selectedplace = PlacePicker.getPlace(this, data);
    for (int i : selectedplace.getPlaceTypes()) {
        if (i == Place.TYPE_DOCTOR || i == Place.TYPE_HEALTH || i == Place.TYPE_HOSPITAL) {
                            isAnHospital = true;
                            break;
                        }
                    }
    
    if(isAnHospital){ 
        //Right type of place
    }else{
        //Tell to the user to select an appropriate place 
          }           
    

    Hope it helps in some way. Sorry for the bad english.

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