PlacePicker 在启动时立即关闭
PlacePicker closes immediatley when launched
我已经在这个问题上停留了很长一段时间,并阅读了 Whosebug 上的所有早期帖子,但是其中 none 已经解决了我的问题。我已经完成了所有提到的事情,但是一旦我启动 placePicker,它就会立即关闭。
我已经提到的帖子是:
- Second one
这里是 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>
我在这个问题上纠结了很长时间。这是我的大学项目。我还成功创建并限制了密钥,如 google 开发者网站所示。任何帮助将不胜感激。
Google Places SDK is Depricated, You need to migrate new API "PLACES
API"
请参考文档..
https://developers.google.com/places/android-sdk/client-migration#place_picker
我已经在这个问题上停留了很长一段时间,并阅读了 Whosebug 上的所有早期帖子,但是其中 none 已经解决了我的问题。我已经完成了所有提到的事情,但是一旦我启动 placePicker,它就会立即关闭。
我已经提到的帖子是:
- Second one
这里是 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>
我在这个问题上纠结了很长时间。这是我的大学项目。我还成功创建并限制了密钥,如 google 开发者网站所示。任何帮助将不胜感激。
Google Places SDK is Depricated, You need to migrate new API "PLACES API"
请参考文档.. https://developers.google.com/places/android-sdk/client-migration#place_picker