gpt4 book ai didi

android - 从 Google map Activity 中获取选定的位置

转载 作者:IT老高 更新时间:2023-10-28 22:00:47 28 4
gpt4 key购买 nike

我正在尝试返回用户在 Google map Android 应用程序中选择的位置,但我似乎无法找到有关如何完成此任务的信息。

我创建了一个 Intent 来打开 GMaps Activity,但用户无法在 map 上选择一个点,该 Activity 在关闭时也不会向我的应用程序返回一个点。

我正在使用 startActiviyForResult,因为我期待 Activity 返回的结果。

最佳答案

您可以简单地使用 PlacePicker而不是实现自己的 MapActivity。不过,您需要在项目中添加 Google Play Services 库引用。

只需使用 PlacePicker.IntentBuilder 提供的 Intent startActivityForResult

int PLACE_PICKER_REQUEST = 1;
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();

Context context = getApplicationContext();
startActivityForResult(builder.build(context), PLACE_PICKER_REQUEST);

然后在onActivityResult中接收结果

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
}
}

请引用 https://developers.google.com/places/android/placepicker了解更多详情。

回答你的问题有点晚了,但希望这可以帮助有同样要求的人。

关于android - 从 Google map Activity 中获取选定的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4430088/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com