baidumaptrace.php,Android 地图跳转到百度、高德、腾讯导航

  • Post author:
  • Post category:php


项目中遇到的一个需求,跳转外部App进行步行导航。分别是百度、高德、腾讯。

东西不难但是每次都要去官方文档找(有时候会更新一些字段)。

所以在此做下记录和分享。

腾讯地图

try {

LatLng latLng=TransBaiduGaodePoint.baidu_to_gaode(new LatLng(Double.parseDouble(lat),Double.parseDouble(lng)));

Uri uri = Uri.parse(“qqmap://map/routeplan?type=walk” +

“&to=” +add//终点的显示名称 必要参数

+”&tocoord=” + latLng.latitude +”,” + latLng.longitude//终点的经纬度

+”&referer=呼唤”);

Intent intent =new Intent();

intent.setData(uri);

baseContext.startActivity(intent);

}catch (Exception e) {

Toast.makeText(baseContext,”请安装腾讯地图”,Toast.LENGTH_SHORT).show();

}

百度地图

LatLng ptStart =new LatLng(Params.latitude, Params.longitude);

LatLng ptEnd =new LatLng(Double.parseDouble(lat), Double.parseDouble(lng));

// 构建 route搜索参数

RouteParaOption para =new RouteParaOption()

.startPoint(ptStart)

.endName(add)

.endPoint(ptEnd);

try {

BaiduMapRoutePlan.openBaiduMapWalkingRoute(para, baseContext);

}catch (Exception e) {

e.printStackTrace();

Toast.makeText(baseContext,”请安装百度地图”,Toast.LENGTH_SHORT).show();

}

高德地图

try {

LatLng latLng=TransBaiduGaodePoint.baidu_to_gaode(new LatLng(Double.parseDouble(lat),Double.parseDouble(lng)));

Uri uri = Uri.parse(“amapuri://route/plan/?dlat=”+latLng.latitude+”&dlon=”+latLng.longitude+”&dname=”+add+”&dev=0&t=2”);

Intent intent =new Intent(“android.intent.action.VIEW”, uri);

intent.addCategory(“android.intent.category.DEFAULT”);

baseContext.startActivity(intent);

}catch (Exception e) {

Toast.makeText(baseContext,”请安装高德地图”,Toast.LENGTH_SHORT).show();

}

坐标转换

注:我的项目中用的是百度地图,所以到高德和腾讯里面会有很多偏差。所以有个坐标转换。

/**

* 将百度坐标转变成火星坐标

*

* @param lngLat_bd 百度坐标(百度地图坐标)

* @return 火星坐标(高德、腾讯地图等)

*/

public static LatLngbaidu_to_gaode(LatLng lngLat_bd) {

double x = lngLat_bd.longitude -0.0065, y = lngLat_bd.latitude -0.006;

double z = Math.sqrt(x * x + y * y) -0.00002 * Math.sin(y *x_pi);

double theta = Math.atan2(y, x) -0.000003 * Math.cos(x *x_pi);

return new LatLng(dataDigit(6, z * Math.sin(theta)), dataDigit(6, z * Math.cos(theta)));

}

最后附上三个地图跳转文档的官方链接

喜欢的朋友可以关注一下