我正在尝试使用谷歌位置选择器,它总是显示RESULT_OK==-1



我的代码
使用此代码调用位置选择器

PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(Checkout.this), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
Milla.log('e',"locationpickerE1",e.getMessage()+"");
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
Milla.log('e',"locationpickerE2",e.getMessage()+"");
} 
int PLACE_PICKER_REQUEST=11290;

添加尝试使用此代码获取位置详细信息

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Milla.log('i',"onActivityResult","iscalled "+PLACE_PICKER_REQUEST+" "+RESULT_OK);
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place selectedPlace = PlacePicker.getPlace(data, this);
Log.i("locationpicker",selectedPlace.getAddress()+"  "+selectedPlace.getLatLng().longitude+"  "+selectedPlace.getLatLng().latitude);
// Do something with the place
}else {
Log.e("locationpicker","not found");
}
}
}

但它总是显示I/onActivityResult: iscalled 11290 -1我检查了权限,没有问题
出了什么问题
它正在工作,允许选择位置,但在活动中未找到任何内容

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
<permission
android:name="rs.fon.mapapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="rs.fon.mapapp.permission.MAPS_RECEIVE" />

您像这样登录Milla.log('i',"onActivityResult","iscalled "+PLACE_PICKER_REQUEST+" "+RESULT_OK);

更改为Milla.log('i',"onActivityResult","iscalled "+requestCode+" "+resultCode);以检查正确的值。。

如果requestCode不等于11290并且resultCode<1>

这是一个主要问题。。

我认为您在片段中使用PlacePicker

如果我是对的,那就改这条线

startActivityForResult(builder.build(Checkout.this), PLACE_PICKER_REQUEST);

getActivity().startActivityForResult(builder.build(Checkout.this), PLACE_PICKER_REQUEST);

相关内容

  • 没有找到相关文章

最新更新