Java Google Places API-地点选取器不等待地点选取
我正在尝试将GooglePlacesAPI合并到我的应用程序中 我已经做了初步的工作,但由于某种原因,当我通过Java Google Places API-地点选取器不等待地点选取,java,android,google-places-api,Java,Android,Google Places Api,我正在尝试将GooglePlacesAPI合并到我的应用程序中 我已经做了初步的工作,但由于某种原因,当我通过 startActivityForResult(Intent,Int) 应用程序将短暂弹出place picker intent,但在用户有机会选择位置并返回“Not OK”Activity.Result之前将关闭 下面是设置活动的代码,与启动联系人选择意图和正常工作几乎完全相同 mApiClient = new GoogleApiClient .Builder(this
startActivityForResult(Intent,Int)代码>
应用程序将短暂弹出place picker intent,但在用户有机会选择位置并返回“Not OK”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[这部分是正确的,但结果代码不正确]
我的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开发者控制台,为您的项目启用Google Places API for Android显示清单文件,问题可能就在那里。您需要按照注册和API密钥说明向AndroidManifest添加API密钥。我已经添加了API密钥,请参阅新添加的清单内容。或者至少我相信我做得对。我是按照那个教程来做的。啊,那里的说明看起来有点混乱-你的清单应该是这样的:你只想把你的API密钥放在这里的API密钥部分。我将在内部提交一个bug来更新这些说明-很抱歉给您带来麻烦!另外,您可能应该从原始帖子中删除该密钥,以便其他人无法使用:)非常感谢!成功了!
<?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>