是否可以通过PlaceId打开Goog​​le Maps? [英] Is It Possible To Open Google Maps By PlaceId?

查看:119
本文介绍了是否可以通过PlaceId打开Goog​​le Maps?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从Google Places API获取的地方ID,目的是像下面的类似方法一样,通过地方ID打开Goog​​le Maps应用

Uri gmmIntentUri = Uri.parse(String.format(Locale.ENGLISH,"geo:%f,%f", lat, lon));
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
    startActivity(mapIntent);
}

有办法吗?

当用户从场所API输入例如艾菲尔铁塔"时,我已经具有经度和纬度.然后,我将这些值存储起来以供下次使用(例如,我们要从本地数据库中列出某种访问过的地点,然后用户单击其中之一,然后应用程序导航至Google Maps)

我有一些担忧

  1. 如果我使用纬度-经度来表示地点而不是地点ID 在Google地图上,如果"Cafe XYZ"移动了另一条街会发生什么 ?

  2. 如果我每次使用地点ID来接收"Cafe XYZ"的最后一个位置 (而不是我的本地数据库中存储的值),该应用很容易达到请求限制

因此,这些担忧使我想到了一种仅发送地点ID Google Maps(例如发送坐标)的方式

解决方案

实际上,有一种方法可以打开带有地点ID的Google Maps应用.为此,您必须使用 Google地图网址 于2017年5月启动.根据Google Maps URL的文档,您可以为艾菲尔铁塔"(位置ID ChIJLU7jZClu5kcR4PcOOO6p3I0)构建以下URL

https://www.google.com/maps/search/?api=1&query=Eiffel%20Tower&query_place_id=ChIJLU7jZClu5kcR4PcOOO6p3I0

因此,您的代码将类似于

Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/search/?api=1&query=Eiffel%20Tower&query_place_id=ChIJLU7jZClu5kcR4PcOOO6p3I0");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
    startActivity(mapIntent);
}

我希望这会有所帮助!

I have a place id obtained from Google Places API, and the aim is opening Google Maps app via place id like similar approach of below

Uri gmmIntentUri = Uri.parse(String.format(Locale.ENGLISH,"geo:%f,%f", lat, lon));
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
    startActivity(mapIntent);
}

Is there a way for this ?

I have already latitude, longitude when user type for example "Eiffel Tower" from places API. And I'm storing those values for next usages(Say we are listing some sort of visited places from local database, and user click one of them and app navigates to Google Maps)

I have a few concerns

  1. If i use latitude-longitude to indicate a place instead of place id on Google Maps, what will happen if "Cafe XYZ" moved another street ?

  2. If i use place id each time to receive last location of "Cafe XYZ" (instead of stored values in my local database) the app easily hit request limits

So those concerns made me think a way that just sending place id Google Maps(like sending coordinates)

解决方案

Indeed, there is a way to open Google Maps app with a place ID. For this purpose you have to use Google Maps URLs that was launched in May 2017. Following the documentation of Google Maps URLs you can construct the following URL for "Eiffel Tower" (place ID ChIJLU7jZClu5kcR4PcOOO6p3I0)

https://www.google.com/maps/search/?api=1&query=Eiffel%20Tower&query_place_id=ChIJLU7jZClu5kcR4PcOOO6p3I0

So, your code will be something like

Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/search/?api=1&query=Eiffel%20Tower&query_place_id=ChIJLU7jZClu5kcR4PcOOO6p3I0");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
if (mapIntent.resolveActivity(getPackageManager()) != null) {
    startActivity(mapIntent);
}

I hope this helps!

这篇关于是否可以通过PlaceId打开Goog​​le Maps?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆