vue 使用定位获取经伟度
一、第一种方法使用百度定位
1.在public处放入
密钥生成方法网上有许多
2.在方法里使用
let that = this; var geolocation = new BMapGL.Geolocation(); // 开启SDK辅助定位 geolocation.enableSDKLocation(); geolocation.getCurrentPosition(function(res) { console.log(res, "获取定位"); });
这样就可以得到定位了
二、使用h5的定位
1.在方法里使用
let that = this; var location_lon = ""; var location_lat = ""; // 经度,纬度 if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { location_lon = position.coords.longitude; location_lat = position.coords.latitude; console.log(location_lon, location_lat, "获取定位"); }); } else { alert("您的设备不支持定位功能"); }
这样就可以得到定位了