log(location.latitude+" "+location.longitude);
Intent intent = new Intent();
intent.setData(Uri.parse("baidumap://map/direction?origin=name:我的位置|latlng:"
+pt1.latitude+","//起始点纬度
+pt1.longitude//起始点经度
+"&destination="
+location.latitude//终点纬度
+","
+location.longitude //终点经度
+"&mode=driving"));
intent.setPackage("com.baidu.BaiduMap");
startActivity(intent); // 启动调用
}
/**
* 启动高德App进行导航
* @param sourceApplication 必填 第三方调用应用名称。如 amap
* @param poiname 非必填 POI 名称
* @param lat 必填 纬度
* @param lon 必填 经度
* @param dev 必填 是否偏移(0:lat 和 lon 是已经加密后的,不需要国测加密; 1:需要国测加密)
* @param style 必填 导航方式(0 速度快; 1 费用少; 2 路程短; 3 不走高速;4 躲避拥堵;5 不走高速且避免收费;6 不走高速且躲避拥堵;7 躲避收费和拥堵;8 不走高速躲避收费和拥堵))
*/
private void gotoGaode(LatLng location){
StringBuffer stringBuffer = new StringBuffer("androidamap://navi?sourceApplication=")
.append(sourceApplication);
stringBuffer.append("&poiname=").append(business.getAddress());
stringBuffer.append("&lat=").append(location.latitude+"")
.append("&lon=").append(location.longitude+"")
.append("&dev=").append(0)
.append("&style=").append("2");
Intent intent = new Intent("android.intent.action.VIEW", android.net.Uri.parse(stringBuffer.toString()));
intent.setPackage("com.autonavi.minimap");
startActivity(intent);
}
调用腾讯地图
private void gotoTen(LatLng location){
double[] to = bd09_To_Gcj02(location.latitude, location.longitude);
double[] from = bd09_To_Gcj02(pt1.latitude, pt1.longitude);
Intent intent = new Intent();
Uri uri = Uri.parse("qqmap://map/routeplan?type=drive&from=我的位置&fromcoord="+from[0]+","
+from[1] +"&to="+business.getAddress()+"&tocoord= "+ to[0]+","+to[1]);
intent.setData(uri);
intent.setPackage("com.tencent.map");
startActivity(intent); //启动调用
}
坐标转换
/** * 坐标转换,腾讯地图(火星坐标)转换成百度地图坐标 * @param lat 腾讯纬度 * @param lon 腾讯经度 * @return 返回结果:经度,纬度 */ public static double[] map_hx2bd(double lat, double lon){ double bd_lat; double bd_lon; double x_pi=3.14159265358979324; double x = lon, y = lat; 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); bd_lon = z * Math.cos(theta) + 0.0065; bd_lat = z * Math.sin(theta) + 0.006; double[] doubles = new double[]{bd_lat,bd_lon}; System.out.println("bd_lat:"+bd_lat); System.out.println("bd_lon:"+bd_lon); return doubles; } /** * 坐标转换,百度地图坐标转换成腾讯地图坐标 * @param lat 百度坐标纬度 * @param lon 百度坐标经度 * @return 返回结果:纬度,经度 */ public static double[] map_bd2hx(double lat, double lon){ double tx_lat; double tx_lon; double x_pi=3.14159265358979324; double x = lon - 0.0065, y = lat - 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); tx_lon = z * Math.cos(theta); tx_lat = z * Math.sin(theta); double[] doubles = new double[]{tx_lat,tx_lon}; return doubles; }