【发布时间】:2019-03-13 14:52:25
【问题描述】:
我已经被这个问题困扰了很长一段时间,并阅读了 stackOverflow 上所有早期的帖子,但是它们都没有解决我的问题。我已经完成了所有提到的事情,但是一旦我启动 placePicker,它就会立即关闭。
我已经被提及的帖子是:
这是 PlacePicker 的代码:
public class Questions extends AppCompatActivity {
Spinner help;
String selectedHelp;
ImageView mapImage;
int PLACE_PICKER = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_questions);
mapImage = (ImageView)findViewById(R.id.map);
Picasso.get().load(R.drawable.map1).into(mapImage);
mapImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selectedHelp.equals("Travel")){
} else {
try {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
startActivityForResult(builder.build(Questions.this), PLACE_PICKER);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (requestCode == PLACE_PICKER){
if (resultCode == RESULT_OK){
Place place = PlacePicker.getPlace(data, this);
String toast = String.format("Place: %s", place.getLatLng());
Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_LONG).show();
Log.i("LatLang: ", toast);
}
}
}}
我的清单:-
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/API_KEY" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Questions">
</activity>
</application>
我在这个问题上纠结了很长时间。这是我的大学项目。我还成功地创建并限制了密钥,如谷歌开发者网站上所示。任何帮助将不胜感激。
【问题讨论】:
-
stackoverflow.com/a/55045772/10579969 这里是使用新地方 API 自动完成的指南
标签: android google-maps google-places-api