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

本文详细介绍了如何在Android应用中通过调用百度地图API实现公交、驾车、步行导航功能,包括检测百度地图安装状态、构建URL并启动地图应用或打开网页版导航的方法。
		Intent intent = null;
		try {// 如果有安装百度地图 就启动百度地图
			StringBuffer sbs = new StringBuffer();
			sbs.append("intent://map/direction?origin=latlng:")
					// 我的位置
					.append(latitude)
					.append(",")
					.append(longitude)
					.append("|name:")
					.append(getResources().getString(R.string.location))
					// 去的位置
					.append("&destination=latlng:")
					.append(overlayItem.getPoint().getLatitudeE6() / 1E6) // 经度
					.append(",")
					.append(overlayItem.getPoint().getLongitudeE6() / 1E6)// 纬度
					.append("|name:")
					.append(overlayItem.getSnippet().replaceAll("nbsp;|&", ""))
					// 城市
					.append("&mode=driving®ion=")
					.append(App.area_name)
					.append("&referer=com.menu|menu#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");
			try {
				intent = Intent.getIntent(sbs.toString());
			} catch (URISyntaxException e) {
				e.printStackTrace();
			}
			startActivity(intent);
		} catch (Exception e) {// 没有百度地图则弹出网页端
			StringBuffer sb = new StringBuffer();
			sb.append("http://api.map.baidu.com/direction?origin=latlng:")
					// 我的位置
					.append(latitude)
					.append(",")
					.append(longitude)
					.append("|name:")
					.append(getResources().getString(R.string.location))
					// 去的位置
					.append("&destination=latlng:")
					.append(overlayItem.getPoint().getLatitudeE6() / 1E6)
					.append(",")
					.append(overlayItem.getPoint().getLongitudeE6() / 1E6)
					.append("|name:")
					.append(overlayItem.getSnippet().replaceAll("nbsp;|&", ""))
					// 城市
					.append("&mode=driving®ion=").append(App.area_name)
					.append("&output=html");
			Uri uri = Uri.parse(sb.toString());
			intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);
		}

根据两个经纬度点调用百度地图应用查询路线 适用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
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值