移动应用中,如何在自己的App中调起第三方的原生地图App,并显示相关的信息,如显示指定的一个坐标位置,显示一个起点到终点的路线查询,等等。
目前几个主要的地图商都提供了自己的App通过URL调用的形式,以下是本人稍微汇总了一下的内容,以备查询。
1、高德地图
示例(iOS):
iosamap://navi?sourceApplication=applicationName&backScheme=applicationScheme&poiname=fangheng&poiid=BGVIS&lat=36.547901&lon=104.258354&dev=1&style=2
详细官方接口说明:
示例(Android):
act=android.intent.action.VIEW cat=android.intent.category.DEFAULT dat=androidamap://navi?sourceApplication=appname&poiname=fangheng&poiid=BGVIS&lat=36.547901&lon=104.258354&dev=1&style=2 pkg=com.autonavi.minimap
详细官方接口说明:
2、百度地图
示例(iOS):
baidumap://map/direction?origin=中关村&destination=五道口&mode=driving®ion=北京 //本示例是通过该URL启动地图app并进入北京市从中关村到五道口的驾车导航路线图
详细官方接口说明:
示例(Android):
intent = Intent.getIntent("intent://map/line?coordtype=&zoom=®ion=上海&name=28&src=yourCompanyName|yourAppName#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end"); //调起百度地图客户端(Android)展示上海市"28"路公交车的检索结果startActivity(intent); //启动调用
详细官方接口说明:
3、Apple Map
示例(iOS):
?daddr=San+Francisco,+CA&saddr=cupertino
详细官方接口说明:
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
4、Google Map
示例(iOS):
comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic
详细官方接口说明:
https://developers.google.com/maps/documentation/ios/urlscheme
示例(Android):
对于Android,是通过Intent形式打开Native Map.
Intent intent=new Intent(Intent.ACTION_VIEW); String url = "https://maps.google.com/maps?q=31.207149,121.593086(金科路)&z=17&hl=en"; Uri uri = Uri.parse(url); intent.setData(uri); startActivity(intent);
详细官方Intent接口说明:
至于URL的参数怎么写,,可以参考Google在iOS文档中对参数的说明。
StackOverflow上有人很好的回答了这个问题:
版权声明:本文为博主原创文章,未经博主允许不得转载。
爱上一个人的时候,总会有点害怕,怕得到他;怕失掉他。