我正在尝试使用 google 位置选择器,它总是显示 RESULT_OK == -1
I am trying to use google location picker and it is always showing 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
我检查了权限,没有问题。
问题是什么 ?
它正在工作,它允许 select 位置,但在 activity
中找不到任何内容
<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 不等于
=30=]-1
这是一个主要问题..
我认为您在片段
中使用了 PlacePicker
如果我是对的,那么只需更改此行
startActivityForResult(builder.build(Checkout.this), PLACE_PICKER_REQUEST);
到
getActivity().startActivityForResult(builder.build(Checkout.this), PLACE_PICKER_REQUEST);
我的代码
使用此代码调用位置选择器
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
我检查了权限,没有问题。
问题是什么 ?
它正在工作,它允许 select 位置,但在 activity
<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 不等于
=30=]-1
这是一个主要问题..
我认为您在片段
中使用了 PlacePicker如果我是对的,那么只需更改此行
startActivityForResult(builder.build(Checkout.this), PLACE_PICKER_REQUEST);
到
getActivity().startActivityForResult(builder.build(Checkout.this), PLACE_PICKER_REQUEST);