我正在尝试将Google Places API合并到我的应用程序中。
我已经完成了初步的事情,但出于某种原因,当我通过
开始活动时 startActivityForResult(Intent, Int);
应用程序会短暂弹出地方选择器意图,但会在用户有机会选择位置并返回“不正常”之前关闭。 Activity.Result。
以下是设置活动的代码以及启动联系人选择意图和工作正常的完全相同的事情,
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();
}
这里是回调,这会返回联系人选择(请求代码= 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();
}
}
我的Android Manifest:
<?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>
答案 0 :(得分:0)
转到Google Developer Console并为您的项目启用适用于Android的Google Places API