2019独角兽企业重金招聘Python工程师标准>>>
高德导航
private void openGaoDeMap(double sLon, double sLat, double dLon, double dLat, String sName, String dName) {try {StringBuilder loc = new StringBuilder();loc.append("androidamap://route?sourceApplication=Sandbox3");loc.append("&slat=");loc.append(sLat);loc.append("&slon=");loc.append(sLon);loc.append("&sname=");loc.append(sName);loc.append("&dlat=");loc.append(dLat);loc.append("&dlon=");loc.append(dLon);loc.append("&dname=");loc.append(dName);loc.append("&dev=0&t=2");Intent intent = Intent.getIntent(loc.toString());startActivity(intent);} catch (Exception e) {e.printStackTrace();}
}
百度导航
private void openBaiduMap(double lon, double lat, String title, String describle) {try {StringBuilder loc = new StringBuilder();loc.append("intent://map/direction?origin=latlng:");loc.append(lat);loc.append(",");loc.append(lon);loc.append("|name:");loc.append("我的位置");loc.append("&destination=latlng:");loc.append(lat);loc.append(",");loc.append(lon);loc.append("|name:");loc.append(describle);loc.append("&mode=driving");loc.append("&referer=Autohome|GasStation#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");Intent intent = Intent.getIntent(loc.toString());if (isInstallPackage("com.baidu.BaiduMap")) {startActivity(intent); //启动调用Log.e("GasStation", "百度地图客户端已经安装");} else {Log.e("GasStation", "没有安装百度地图客户端");}} catch (Exception e) {e.printStackTrace();}
}
转换坐标 高德转百度 百度转高德
public class AMapUtils {public static boolean isInstallPackage(String packageName) {return new File("/data/data/" + packageName).exists();}public static double[] bdToGaoDe(double bd_lat, double bd_lon) {double[] gd_lat_lon = new double[2];double PI = 3.14159265358979324 * 3000.0 / 180.0;double x = bd_lon - 0.0065, y = bd_lat - 0.006;double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * PI);double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * PI);gd_lat_lon[0] = z * Math.cos(theta);gd_lat_lon[1] = z * Math.sin(theta);return gd_lat_lon;}public static double[] gaoDeToBaidu(double gd_lon, double gd_lat) {double[] bd_lat_lon = new double[2];double PI = 3.14159265358979324 * 3000.0 / 180.0;double x = gd_lon, y = gd_lat;double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * PI);double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * PI);bd_lat_lon[0] = z * Math.cos(theta) + 0.0065;bd_lat_lon[1] = z * Math.sin(theta) + 0.006;return bd_lat_lon;}/*** 检查手机上是否安装了指定的软件** @param context* @param packageName:应用包名* @return*/public static boolean isAvilible(Context context, String packageName) {//获取packagemanagerfinal PackageManager packageManager = context.getPackageManager();//获取所有已安装程序的包信息List 调用网页高德地图 StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("http://uri.amap.com/navigation?from=");
stringBuffer.append(myLatLng.longitude);
stringBuffer.append(",");
stringBuffer.append(myLatLng.latitude);
stringBuffer.append(",startpoint&to=");
stringBuffer.append(destLatLng.longitude);
stringBuffer.append(",");
stringBuffer.append(destLatLng.latitude);
stringBuffer.append(",endpoint");
stringBuffer.append("&mode=car&policy=1&src=mypage&coordinate=gaode&callnative=0");