Android 从超链接打开谷歌地图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10204612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open google maps from hyperlink
提问by opc0de
I am trying to design a webpage specially for android users so i was wondering if there is a hyper link format that can open up google maps just like the call function eg
我正在尝试专门为 android 用户设计一个网页,所以我想知道是否有一种超链接格式可以像调用函数一样打开谷歌地图,例如
<a href="tel:0766551121"> Call me now </a>
回答by bitek
If by "open up Google Maps" you mean the native Android Google Maps application instead of opening the link in the Android's browser then according to Geo Intentsyou can use the following Geo URIformats that trigger intents that will open the Google Maps application on the device to the given location or query:
如果“打开谷歌地图”是指原生 Android 谷歌地图应用程序,而不是在 Android 浏览器中打开链接,那么根据Geo Intents,您可以使用以下Geo URI格式触发意图,从而在设备到给定位置或查询:
- geo:latitude,longitude
- geo:latitude,longitude?z=zoom
- geo:0,0?q=my+street+address
- geo:0,0?q=business+near+city
- 地理:纬度,经度
- 地理:纬度,经度?z=缩放
- geo:0,0?q=我的+街道+地址
- geo:0,0?q=business+near+city
For Google Streetview you can use:
对于谷歌街景,您可以使用:
- google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom
- google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom
For details on the available options see the official Google Maps Intents documentation
有关可用选项的详细信息,请参阅官方 Google Maps Intents 文档
回答by ρяσ?ρ?я K
回答by Arpit Patel
I am going with @Mnemonic Flow
我要使用@Mnemonic Flow
- geo:latitude,longitude
- geo:latitude,longitude?z=zoom
- geo:0,0?q=my+street+address
- geo:0,0?q=business+near+city
- 地理:纬度,经度
- 地理:纬度,经度?z=缩放
- geo:0,0?q=我的+街道+地址
- geo:0,0?q=business+near+city
Create your Uri
创建你的 Uri
Example
例子
Step 1 :Create link like
第 1 步:创建链接,如
Uri uri;
geo:latitude,longitude
uri = Uri.parse("geo:47.6,-122.3")
geo:latitude,longitude?z=zoom
uri = Uri.parse("geo:47.6,-122.3?z=11")
geo:0,0?q=my+street+address
uri = Uri.parse("geo:0,0q=The+Eldorado+Park,+Rampar+Mota,+Gujarat,+India")
geo:0,0?q=business+near+city
uri = Uri.parse("geo:0,0q=The+Eldorado+Park,+Rampar+Mota,+Gujarat,+India")
地理:纬度,经度
uri = Uri.parse("geo:47.6,-122.3")
地理:纬度,经度?z=缩放
uri = Uri.parse("geo:47.6,-122.3?z=11")
geo:0,0?q=我的+街道+地址
uri = Uri.parse("geo:0,0q=The+Eldorado+Park,+Rampar+Mota,+Gujarat,+India")
geo:0,0?q=business+near+city
uri = Uri.parse("geo:0,0q=The+Eldorado+Park,+Rampar+Mota,+Gujarat,+India")
Step 1Create method like below
步骤 1创建如下方法
public void showMap(Uri geoLocation) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
And Call like this
像这样打电话
showMap(uri);
Step 2 :Add intent-filter in you manifiest file
第 2 步:在您的清单文件中添加意图过滤器
<activity YourActivity>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="geo" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>