无法通过Android Place Picker选择Place

时间:2015-11-15 09:21:41

标签: android google-places-api

我试图在我的应用中使用地方选择器。通过使用此代码,我可以看到地方选择器在地图上显示我当前的位置但无法选择地点。

 public class MapsActivity extends Activity {

  @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.location_task);
   }

  private static final int REQUEST_PLACE_PICKER = 1;

  public void onPickButtonClick(View v) {
           // Construct an intent for the place picker
    try {
        PlacePicker.IntentBuilder intentBuilder =
                new PlacePicker.IntentBuilder();
        Intent intent = intentBuilder.build(this);
            // Start the intent by requesting a result,
            // identified by a request code.
        startActivityForResult(intent, REQUEST_PLACE_PICKER);
    } catch (GooglePlayServicesRepairableException e) {

    } catch (GooglePlayServicesNotAvailableException e) {

    }
  }
  @Override
   protected void onActivityResult(int requestCode,
                                int resultCode, Intent data) {
       if (requestCode == REQUEST_PLACE_PICKER) {if (resultCode == RESULT_OK) {
        Place place = PlacePicker.getPlace(data, this);
        String toastMsg = String.format("Place: %s", place.getName());
        Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
       }

       } else {
        super.onActivityResult(requestCode, resultCode, data);
     }
}

Here is output

0 个答案:

没有答案