Android开发中经常会集成地图,可以直接接入SDK进行开发,也可以调起地图传参数实现各种功能。
调起地图并传经纬度进行导航
//百度地图,log纬度,lat经度
Intent i1 = new Intent();
if (StringUtil.isEmpty(log) || StringUtil.isEmpty(lat)){i1.setData(Uri.parse("baidumap://map?"));
}else{//i1.setData(Uri.parse("baidumap://map/navi?query=" + MyApplication.app.getOrderDesc()));//传地址进行导航i1.setData(Uri.parse("baidumap://map/navi?location= " + lat + " ," + log));//传经纬度进行导航
}
MyApplication.context.startActivity(i1);//高德地图车机版,需要转换成火星坐标
double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
double x = Double.parseDouble(log) - 0.0065, y = Double.parseDouble(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);
double lons = dataDigit(6,z * Math.cos(theta));
double lats = dataDigit(6,z * Math.sin(theta));
intent = new Intent();
intent.setAction("AUTONAVI_STANDARD_BROADCAST_RECV");
intent.putExtra("KEY_TYPE", 10038);
intent.putExtra("POINAME",desc.trim());
intent.putExtra("LAT",lats);
intent.putExtra("LON",lons);
intent.putExtra("DEV",0);
intent.putExtra("STYLE",0);
intent.putExtra("SOURCE_APP","Third App");
MyApplication.context.sendBroadcast(intent);
System.out.println("=========高德地图========log:" + lons + ",lat:" + lats + ",desc:" + desc);//转换经纬度
public double dataDigit(int digit, double in){return new BigDecimal(in).setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
}
调用之前一定要先判断安装了百度地图、高德地图apk
/**判断是否安装了应用*/
public static boolean hasInstallApk(String pakacge){if (new File("/data/data/" + pakacge).exists()){return true;}return false;
}