[英]Google Places API - Place Picker not waiting for place pick
I am trying to incorporate Google Places API into my application. 我正在尝试将Google Places API整合到我的应用程序中。
I have done the preliminary things but for some reason when I start the activity via 我已经做了一些初步的准备,但是由于某种原因,当我通过以下方式开始活动时
startActivityForResult(Intent, Int);
The application will briefly pop up the place picker intent but will close before the user has the opportunity to select a location and returns a 'Not OK' Activity.Result. 该应用程序将短暂弹出位置选择器的意图,但在用户有机会选择位置并返回“不正确” Activity.Result之前将关闭。
Here is the code to set up the activity along with almost the exact same thing launching a contact select intent and working fine, 这是设置活动的代码,几乎完全相同,可以启动联系人选择意图并可以正常工作,
mApiClient = new GoogleApiClient
.Builder(this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Intent intent = getIntent();
getIntentData(intent);
/*Contact Select, works fine*/
int resulter = 3;
Intent intenter = new Intent(Intent.ACTION_PICK, Uri.parse("content://contact"));
intenter.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intenter, resulter);
try {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
and here is the callback, this returns the correct information for the contact select (request code = 3) but incorrect information for the Place Picker (request code = 2 [this part is correct, but the result code is incorrect]), 这是回调,它将返回有关联系人选择的正确信息(请求代码= 3),但有关位置选择器的信息不正确(请求代码= 2 [此部分正确,但是结果代码不正确]),
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == Activity.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 if (requestCode == 3) {
Toast.makeText(this, "wwhhhahahahahahahahahaah", Toast.LENGTH_LONG).show();
}
}
My Android Manifest: 我的Android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hytexsoftware.dummy" >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="API_KEY"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name=".LoadScreen"
android:label="@string/title_activity_load_screen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MapView"
android:label="@string/title_activity_map_view" >
</activity>
<activity
android:name=".DisplayLocations"
android:label="@string/title_activity_display_locations" >
</activity>
<activity
android:name=".util.ShowLocationOnMap"
android:label="@string/title_activity_show_location_on_map" >
</activity>
</application>
</manifest>
转到Google Developer Console,为您的项目启用Android版Google Places API
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.