百度地图----浏览器定位获得详细地址
浏览器定位获得详细地址
// 百度地图API功能var point = null;var map = new BMap.Map("l-map");map.centerAndZoom(new BMap.Point(116.395645,39.929986), 7);map.enableScrollWheelZoom(true);//获取浏览器定位var geolocation = new BMap.Geolocation();geolocation.getCurrentPosition(function(res){if(res){alert(JSON.stringify(res.point));point = res.point;analysis(res.point);// map.centerAndZoom(new BMap.Point(res.point.lng,res.point.lat),12);}});//解析经纬度function analysis(pt){var geoc = new BMap.Geocoder();geoc.getLocation(new BMap.Point(pt.lng,pt.lat),function(res){alert(res.addressComponents.city.substring(0,2));map.centerAndZoom(res.address,12);geoc.getPoint(res.address, function(pt){pt && addMarker(new BMap.Point(pt.lng, pt.lat),new BMap.Label( res.address , {offset:new BMap.Size(20,-10)}));}, "中国");// map.addOverlay(new BMap.Marker(pt.lng,pt.lat),new BMap.Label(res.address, {offset:new BMap.Size(20,-10)}));});}function addMarker(point,label){// 编写自定义函数,创建标注var marker = new BMap.Marker(point);map.addOverlay(marker);marker.setLabel(label);// marker.setAnimation(BMAP_ANIMATION_BOUNCE);//图标动画}
demo效果
demo下载
其他
我的博客,欢迎交流!
我的CSDN博客,欢迎交流!
微信小程序专栏
前端笔记专栏
微信小程序实现部分高德地图功能的DEMO下载
微信小程序实现MUI的部分效果的DEMO下载
微信小程序实现MUI的GIT项目地址
微信小程序实例列表
前端笔记列表
游戏列表
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
