Google 地图应用中未显示地理意图标签
Geo Intent Label not showing in Google Maps App
由于我的 Google 地图应用最近更新,现在 版本 10.11.1,以下代码未按预期显示标签,documented,以前工作过:
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("geo:38.8951,100.0364?q=38.8951,100.0364(foo)")).setPackage("com.google.android.apps.maps")
if (intent.resolveActivity(packageManager) == null) {
intent.setPackage(null)
}
startActivity(intent)
这个版本也没有(0,0
紧跟在 geo:
之后):
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=38.8951,100.0364(foo)")).setPackage("com.google.android.apps.maps")
if (intent.resolveActivity(packageManager) == null) {
intent.setPackage(null)
}
startActivity(intent)
official documentation 中的示例代码也没有显示标签:
// Display a label at the location of Google's Sydney office
Uri gmmIntentUri = Uri.parse("geo:0,0?q=-33.8666,151.1957(Google+Sydney)");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
更新:计划于 2022 年 1 月底之前在 v11.12 中修复。
即使使用最新的地图更新 10.12.1 仍然没有解决方案即使文档仍然说应该显示,标签仍然没有显示
我在 Google 的问题跟踪器上创建了一个问题:https://issuetracker.google.com/issues/129726279
希望我们很快就会有一些信息。
我想我们走错了路。如果我是 Google,我也会对允许开发人员 post 带有抽象目的地标签的方向感到不安全,我相信他们永远不会计划解决这个问题。
根据Google的新标准,我推荐以下解决方案。 https://developers.google.com/maps/documentation/urls/android-intents:
https://www.google.com/maps/dir/?api=1&destination=LATITUDE,LONGITUDE
如果你现在看看大多数应用程序,包括我构建的应用程序,这允许我们 post 一个 LAT/LONG 供用户使用 Google自己的地址值内置为目标标签。
要实际启动 Google 地图应用程序,只需启动一个 Web Intent,在本例中我使用应用程序上下文。
fun startGoogleMaps(context: Context, lat: Double, long: Double) {
startWebBrowser(
context,
Uri.parse("https://www.google.com/maps/dir/?api=1&destination=$lat,$long")
)
}
fun startWebBrowser(context: Context, link: Uri?) {
if (link != null) {
val webIntent = Intent(Intent.ACTION_VIEW, link).apply {
addFlags(FLAG_ACTIVITY_NEW_TASK)
}
if (webIntent.resolveActivity(context.packageManager) != null) {
context.startActivity(webIntent)
}
}
}
Per Google,这是 Google 地图应用程序中的错误。它已在版本 11.12 中修复。
由于我的 Google 地图应用最近更新,现在 版本 10.11.1,以下代码未按预期显示标签,documented,以前工作过:
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("geo:38.8951,100.0364?q=38.8951,100.0364(foo)")).setPackage("com.google.android.apps.maps")
if (intent.resolveActivity(packageManager) == null) {
intent.setPackage(null)
}
startActivity(intent)
这个版本也没有(0,0
紧跟在 geo:
之后):
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=38.8951,100.0364(foo)")).setPackage("com.google.android.apps.maps")
if (intent.resolveActivity(packageManager) == null) {
intent.setPackage(null)
}
startActivity(intent)
official documentation 中的示例代码也没有显示标签:
// Display a label at the location of Google's Sydney office
Uri gmmIntentUri = Uri.parse("geo:0,0?q=-33.8666,151.1957(Google+Sydney)");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
更新:计划于 2022 年 1 月底之前在 v11.12 中修复。
即使使用最新的地图更新 10.12.1 仍然没有解决方案即使文档仍然说应该显示,标签仍然没有显示 我在 Google 的问题跟踪器上创建了一个问题:https://issuetracker.google.com/issues/129726279
希望我们很快就会有一些信息。
我想我们走错了路。如果我是 Google,我也会对允许开发人员 post 带有抽象目的地标签的方向感到不安全,我相信他们永远不会计划解决这个问题。
根据Google的新标准,我推荐以下解决方案。 https://developers.google.com/maps/documentation/urls/android-intents:
https://www.google.com/maps/dir/?api=1&destination=LATITUDE,LONGITUDE
如果你现在看看大多数应用程序,包括我构建的应用程序,这允许我们 post 一个 LAT/LONG 供用户使用 Google自己的地址值内置为目标标签。
要实际启动 Google 地图应用程序,只需启动一个 Web Intent,在本例中我使用应用程序上下文。
fun startGoogleMaps(context: Context, lat: Double, long: Double) {
startWebBrowser(
context,
Uri.parse("https://www.google.com/maps/dir/?api=1&destination=$lat,$long")
)
}
fun startWebBrowser(context: Context, link: Uri?) {
if (link != null) {
val webIntent = Intent(Intent.ACTION_VIEW, link).apply {
addFlags(FLAG_ACTIVITY_NEW_TASK)
}
if (webIntent.resolveActivity(context.packageManager) != null) {
context.startActivity(webIntent)
}
}
}
Per Google,这是 Google 地图应用程序中的错误。它已在版本 11.12 中修复。