基于百度地图api实现的起终点路线规划和自定义覆盖物启动APP
来源:互联网 发布:淘宝已售罄是什么意思 编辑:程序博客网 时间:2024/05/07 13:08
效果图
本人也是第一次做和百度地图相关的项目,这个效果有需要注意
1.起点和终点之间的路线是根据驾车路线规划出来的
2.导航是自定义的覆盖物
3.起点的位置是让浏览器自动获取
废话不多说,直接上代码
// 百度地图API功能start
var map = new BMap.Map(“allmap”);
(function() {
//初始化地图 默认加载北京天安门;初始化地图,point为中心点,缩放级别为16
map.centerAndZoom(new BMap.Point(116.331398, 39.897445), 11);
//判断手机浏览器是否支持定位
if(navigator.geolocation){
var geolocation = new BMap.Geolocation();//创建定位实例
geolocation.getCurrentPosition(showLocation,{enableHighAccuracy: true});//enableHighAccuracy 要求浏览器获取最佳结果
}else{
map.addControl(new BMap.GeolocationControl());//添加定位控件 支持定位
}
});
//处理定位后的信息
function showLocation(r){
if(this.getStatus() == BMAP_STATUS_SUCCESS){//定位成功
var p1 = new BMap.Point(r.longitude,r.latitude);//定位位置
var p2 = new BMap.Point(shop_goods.Longitude
map.panTo(p1);//拖拽 map.setCenter(p1);//等比例缩放 var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}}); driving.search(p1, p2);// 复杂的自定义覆盖物function ComplexCustomOverlay(point, text, mouseoverText){ this._point = point; this._text = text;}ComplexCustomOverlay.prototype = new BMap.Overlay();ComplexCustomOverlay.prototype.initialize = function(map){ this._map = map; var div = this._div = document.createElement("a"); div.setAttribute("class","open_appBtn" ); div.setAttribute("href","baidumap://map/direction?origin="+r.latitude+","+r.longitude+"|name:我的位置&destination=$shop_goods.Latitude$,$shop_goods.Longitude$&mode=driving&src=webapp.navi.yourCompanyName.yourAppName"); div.style.display = "block"; div.style.position = "absolute"; div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat); div.style.backgroundColor = "#EE5D5B"; div.style.border = "1px solid #BC3B3A"; div.style.color = "white"; div.style.width = "50px"; div.style.height = "18px"; div.style.padding = "2px"; div.style.lineHeight = "18px"; div.style.whiteSpace = "nowrap"; div.style.MozUserSelect = "none"; div.style.fontSize = "12px"; div.style.textAlign="center"; div.style.zIndex = "99999"; var span = this._span = document.createElement("span"); div.appendChild(span); span.appendChild(document.createTextNode(this._text)); var that = this; var arrow = this._arrow = document.createElement("span"); arrow.style.display = "block"; arrow.style.background = "url(http://map.baidu.com/fwmap/upload/r/map/fwmap/static/house/images/label.png) no-repeat"; arrow.style.position = "absolute"; arrow.style.width = "11px"; arrow.style.height = "10px"; arrow.style.top = "22px"; arrow.style.left = "20px"; arrow.style.overflow = "hidden"; div.appendChild(arrow); map.getPanes().labelPane.appendChild(div); return div;}// 实现绘制方法 ComplexCustomOverlay.prototype.draw = function(){// 根据地理坐标转换为像素坐标,并设置给容器 var map = this._map; var pixel = map.pointToOverlayPixel(this._point); this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px"; this._div.style.top = pixel.y - 66 + "px";}var myCompOverlay = new ComplexCustomOverlay(p2, "导航");map.addOverlay(myCompOverlay);var _marker01 = myCompOverlay; //当初存的覆盖物变量,这里派上用场了。
map.addEventListener(“touchstart”,function(e){
var element= e.domEvent.srcElement
element.click();
})
}else { alert('failed'+this.getStatus());//定位失败}
}
// 百度地图API功能end
需要注意的是:
- 基于百度地图api实现的起终点路线规划和自定义覆盖物启动APP
- android开发游记:百度地图SDK路线规划和自定义地图UI覆盖物及弹出窗
- 百度地图路线规划功能的实现
- 百度地图API制作类似 百度地图的路线导航界面并实现简单的路线规划功能
- 百度地图JS版API自定义覆盖物和控件
- 百度地图实现路线规划
- 百度地图api实现路线规划之步行驾车
- 百度地图API-自定义图标覆盖物
- 基于百度地图,绘制自定义覆盖物
- JS版]基于百度地图的 Overlay 扩展,仿Q房网实现自定义覆盖物
- 百度地图的路线规划
- 百度地图api之路线规划
- web百度地图API路线规划+导航
- 百度地图api绘制路线规划实例
- 百度地图自定义多点规划路线
- 百度地图实现根据路线添加覆盖物
- 百度地图开发第三天(起始点和终点的路线查询)
- 百度地图接口,根据起点和终点做路径规划
- Python----一个对象的属性可以是另外一个类型创建的对象
- Django-restframework20 Validators验证类
- javaweb项目登录注册界面验证码动态生成展示
- 通过js模拟用户按F5刷新页面效果
- tinyOS
- 基于百度地图api实现的起终点路线规划和自定义覆盖物启动APP
- 前端性能优化方案
- python实现最简单循环神经网络(RNNs)
- Django-restframework21 Authentication认证类
- 全都开源了,还怎么赚钱?----卖技术服务啊!
- SQL Server完全卸载
- Yolo2代码解析
- Elasticsearch 中文分词器 IK 配置和使用
- 文本索引API GroupDocs.Search for .NET 11月新版17.11发布