2016-08-18 62 views
1

該Place.class包括城市,國家,地址和帖子,但我想 分開them.Thank!Google Place Picker得到的城市?

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

     if(resultCode==RESULT_OK){ 
     final Place place = PlacePicker.getPlace(this,data); 
     final CharSequence name = place.getName(); 
     final String address = place.getAddress()+""; 
     String attributions = (String) place.getAttributions(); 
     if (attributions == null) { 
      attributions = ""; 
     } 
     et_city.setText(address); 
     et_post.setText(address); 
     et_street.setText(address); 
     } 
    } 
+0

你能夠得到所需的細節?你能接受答案嗎? –

回答

3

嘗試這樣做

final Place place = PlacePicker.getPlace(this,data); 
Geocoder geocoder = new Geocoder(this); 
try 
{ 
    List<Address> addresses = geocoder.getFromLocation(place.getLatLng().latitude,place.getLatLng().longitude, 1); 
    String address = addresses.get(0).getAddressLine(0); 
    String city = addresses.get(0).getAddressLine(1); 
    //String country = addresses.get(0).getAddressLine(2); 

} catch (IOException e) 
{ 
    bottomSheetAddress.setText("Not Available."); 
    e.printStackTrace(); 
} 
+0

* Geocoder *是Google API插件的一部分,不屬於AOSP的一部分。 –

0

我已經回答了同樣的問題,可能會幫助你。你可以找到它here.

相關問題