根据两个经纬度点调用百度地图应用查询路线 适用android或者ios中及网页浏览(手机网页同样适用)



根据两个经纬度点调用百度地图应用查询路线 适用android或者ios中及网页浏览(手机网页同样适用)

  1. Intent intent = null;
  2. try {// 如果有安装百度地图 就启动百度地图
  3.     StringBuffer sbs = new StringBuffer();
  4.     sbs.append(“intent://map/direction?origin=latlng:”)
  5.             // 我的位置
  6.             .append(latitude)
  7.             .append(“,”)
  8.             .append(longitude)
  9.             .append(“|name:”)
  10.             .append(getResources().getString(R.string.location))
  11.             // 去的位置
  12.             .append(“&destination=latlng:”)
  13.             .append(overlayItem.getPoint().getLatitudeE6() / 1E6) // 经度
  14.             .append(“,”)
  15.             .append(overlayItem.getPoint().getLongitudeE6() / 1E6)// 纬度
  16.             .append(“|name:”)
  17.             .append(overlayItem.getSnippet().replaceAll(“nbsp;|&”, ”"))
  18.             // 城市
  19.             .append(“&mode=driving®ion=”)
  20.             .append(App.area_name)
  21.             .append(“&referer=com.menu|menu#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end”);
  22.     try {
  23.         intent = Intent.getIntent(sbs.toString());
  24.     } catch (URISyntaxException e) {
  25.         e.printStackTrace();
  26.     }
  27.     startActivity(intent);
  28. } catch (Exception e) {// 没有百度地图则弹出网页端
  29.     StringBuffer sb = new StringBuffer();
  30.     sb.append(“http://api.map.baidu.com/direction?origin=latlng:”)
  31.             // 我的位置
  32.             .append(latitude)
  33.             .append(“,”)
  34.             .append(longitude)
  35.             .append(“|name:”)
  36.             .append(getResources().getString(R.string.location))
  37.             // 去的位置
  38.             .append(“&destination=latlng:”)
  39.             .append(overlayItem.getPoint().getLatitudeE6() / 1E6)
  40.             .append(“,”)
  41.             .append(overlayItem.getPoint().getLongitudeE6() / 1E6)
  42.             .append(“|name:”)
  43.             .append(overlayItem.getSnippet().replaceAll(“nbsp;|&”, ”"))
  44.             // 城市
  45.             .append(“&mode=driving®ion=”).append(App.area_name)
  46.             .append(“&output=html”);
  47.     Uri uri = Uri.parse(sb.toString());
  48.     intent = new Intent(Intent.ACTION_VIEW, uri);
  49.     startActivity(intent);
  50. }

根据两个经纬度点调用百度地图应用查询路线 适用android或者ios中及网页浏览(手机网页同样适用)

检测是否安装百度地图 不过我这种捕获异常的方式检测百度地图是否安装不太好 来读取安装程序中是否有百度地图的方式比较正确 不过没必要 还是异常捕获吧

在应用中试了好多次才通过 写一个博客记录一下

ios怎么获取连接同上


 

3.7 公交、驾车、步行导航

3.7.1 服务地址

 

 

http://api.map.baidu.com/direction   //PC&Webapp服务地址
intent://map/direction     //Android服务地址
baidumap://map/direction    // iOS服务地址
百度URI API 地址:http://developer.baidu.com/map/uri-intro.htm