|
发表于 2016-8-15 18:17:55
|
显示全部楼层
- window._baiduInit = function() {var longitude, latitude; var map = new BMap.Map(id); // 创建地图对象,可以设置地图缩放最大最小级别,设置是否显示POI点击 var geoc = new BMap.Geocoder(); // 116.468439,39.871337 var geol = new BMap.Geolocation(); if (addrPoint) { var nowPoint = new BMap.Point(addrPoint.lng, addrPoint.lat); map.centerAndZoom(new BMap.Point(addrPoint.lng, addrPoint.lat), 17); map.setCurrentCity("北京"); map.disableDragging();// 禁止拖拽地图 map.disableDoubleClickZoom()// 禁止双击方法地图你 var marker = new BMap.Marker(nowPoint); map.addOverlay(marker); geoc.getLocation(nowPoint, function(rs) { mainData.setValue("address", addr); }) } else { var success = function(data) { var coorType = data.coorType || "gps"; var longitude = data.coords.longitude; var latitude = data.coords.latitude; if(coorType == "bd09ll"){ var nowPoint = new BMap.Point(longitude, latitude); map.centerAndZoom(nowPoint, 17); map.setCurrentCity("北京"); map.disableDragging();// 禁止拖拽地图 map.disableDoubleClickZoom()// 禁止双击放大地图你 var marker = new BMap.Marker(nowPoint); map.addOverlay(marker); geoc.getLocation(nowPoint, function(rs) { mainData.setValue("address", rs.address + rs.surroundingPois[0].title); }) }else if(coorType == "gps"){ $.ajax({ method: "GET", url:"/baas/bmap/api/convertLocation", cache:false, data:{ longitude:longitude, latitude:latitude } }).done(function(result) { var bmapResult = JSON.parse(result); var lon = bmapResult.result[0].x; var lat = bmapResult.result[0].y; var nowPoint = new BMap.Point(lon, lat); map.centerAndZoom(nowPoint, 17); map.setCurrentCity("北京"); map.disableDragging();// 禁止拖拽地图 map.disableDoubleClickZoom()// 禁止双击放大地图你 var marker = new BMap.Marker(nowPoint); map.addOverlay(marker); geoc.getLocation(nowPoint, function(rs) { mainData.setValue("address", rs.address + rs.surroundingPois[0].title); }) }) } }; var fail = function(e) { // justep.Util.hint("获取地理位置失败,暂时采用默认地址"); // var map = new BMap.Map(id); // map.centerAndZoom(new BMap.Point(116.468497,39.871319), 17); // map.setCurrentCity("北京"); // map.disableDragging();// 禁止拖拽地图 // map.disableDoubleClickZoom()// 禁止双击方法地图你 // var marker = new BMap.Marker(new BMap.Point(116.468497,39.871319)); // map.addOverlay(marker); // geoc.getLocation(new BMap.Point(116.468497,39.871319), function(rs) { // mainData.setValue("address", rs.address + rs.surroundingPois[0].title); // }) justep.Util.hint("获取地理位置失败!请尝试设置应用权限"); }; navigator.geolocation.getCurrentPosition(success, fail); } }
复制代码 |
|