0

我正在使用Android提供的最新Place Picker控件。它非常易於使用。我可以將Android的PlacePicker控件限制到特定的國家嗎?

現在的問題是:

1.我可以限制搜索區域只有印度?

2.我可以改變它駐留在PlacePicker控件的默認標記圖標?

注意:我沒有使用任何mapView或Fragment來顯示任何地圖。我使用的是PlacePicker,而不是使用GoogleMap。

回答

0
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == PLACE_PICKER_REQUEST) { 
     if (resultCode == RESULT_OK) { 
      Place place = PlacePicker.getPlace(mActivity, data); 
      Log.d(TAG, "onActivityResult: " + place.getAddress()); 
      if (place.getAddress() != null) { 
       // ask for geolocation data 
       Geocoder gcd = new Geocoder(mActivity, Locale.getDefault()); 

       try { 
        addresses = gcd.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 


       if (addresses.size() > 0) { 
        if (addresses.get(0).getCountryCode().equalsIgnoreCase(getString(R.string.india))) { 
         //write the code here 
        } else { 
         Toast.makeText(mActivity, "Invalid places", Toast.LENGTH_SHORT).show(); 
        } 
       } 
      } 
     } 
    } 
} 
+0

不是一個可靠的方法只是一個解決方案,以便它在一定程度上有效。 – tom030888

相關問題