| | |
| | | import { Message } from "element-ui"; |
| | | import { |
| | | Message |
| | | } from "element-ui"; |
| | | // import BMap from "./mobilePositionLID"; |
| | | import RemoGeoLocation from "./mobilePositionLID1"; |
| | | |
| | | const mobilePosition = { |
| | | state: { getSPosition: null }, |
| | | state: { |
| | | getSPosition: null |
| | | }, |
| | | mutations: { |
| | | GET_NOWPOSITION(state, val) { |
| | | let outData = |
| | |
| | | return timeFn; |
| | | }; |
| | | if (navigator.geolocation) { |
| | | let success = function (position) { |
| | | console.log(position); |
| | | times(startTime); |
| | | var lat = position.coords.latitude; |
| | | var lon = position.coords.longitude; |
| | | console.log("成功返回经纬度信息"); |
| | | // Message({ |
| | | // showClose: true, |
| | | // message: |
| | | // "成功返回经纬度信息(1)" + |
| | | // lon + |
| | | // "_" + |
| | | // lat + |
| | | // "--反应时间:" + |
| | | // times(startTime), |
| | | // type: "success", |
| | | // duration: 0, |
| | | // }); |
| | | console.log(lon, lat, "成功"); |
| | | outData([lon, lat]); |
| | | }; |
| | | let error = function (error) { |
| | | // console.log(error, "失败"); |
| | | outData(["失败", "失败"]); |
| | | let msg = "none"; |
| | | switch (error.code) { |
| | | case error.PERMISSION_DENIED: |
| | | msg = "User denied the request for Geolocation."; |
| | | break; |
| | | case error.POSITION_UNAVAILABLE: |
| | | msg = "Location information is unavailable."; |
| | | break; |
| | | case error.TIMEOUT: |
| | | msg = "The request to get user location timed out."; |
| | | break; |
| | | case error.UNKNOWN_ERROR: |
| | | msg = "An unknown error occurred."; |
| | | break; |
| | | } |
| | | // Message({ |
| | | // showClose: true, |
| | | // message: |
| | | // "定位获取失败-msg:" + |
| | | // msg + |
| | | // "------" + |
| | | // error.message + |
| | | // "--反应时间:" + |
| | | // times(startTime), |
| | | // type: "error", |
| | | // duration: 0, |
| | | // }); |
| | | Message({ |
| | | showClose: true, |
| | | message: "未开启位置权限", |
| | | type: "error", |
| | | duration: 2000, |
| | | }); |
| | | }; |
| | | let options = { |
| | | enableHighAccuracy: true, |
| | | // timeout: 5000, |
| | | timeout: Infinity, |
| | | maximumAge: 0, |
| | | }; |
| | | // let success = function (position) { |
| | | // console.log(position); |
| | | // times(startTime); |
| | | // var lat = position.coords.latitude; |
| | | // var lon = position.coords.longitude; |
| | | // console.log("成功返回经纬度信息"); |
| | | // // Message({ |
| | | // // showClose: true, |
| | | // // message: |
| | | // // "成功返回经纬度信息(1)" + |
| | | // // lon + |
| | | // // "_" + |
| | | // // lat + |
| | | // // "--反应时间:" + |
| | | // // times(startTime), |
| | | // // type: "success", |
| | | // // duration: 0, |
| | | // // }); |
| | | // console.log(lon, lat, "成功"); |
| | | // outData([lon, lat]); |
| | | // }; |
| | | // let error = function (error) { |
| | | // // console.log(error, "失败"); |
| | | // outData(["失败", "失败"]); |
| | | // let msg = "none"; |
| | | // switch (error.code) { |
| | | // case error.PERMISSION_DENIED: |
| | | // msg = "User denied the request for Geolocation."; |
| | | // break; |
| | | // case error.POSITION_UNAVAILABLE: |
| | | // msg = "Location information is unavailable."; |
| | | // break; |
| | | // case error.TIMEOUT: |
| | | // msg = "The request to get user location timed out."; |
| | | // break; |
| | | // case error.UNKNOWN_ERROR: |
| | | // msg = "An unknown error occurred."; |
| | | // break; |
| | | // } |
| | | // // Message({ |
| | | // // showClose: true, |
| | | // // message: |
| | | // // "定位获取失败-msg:" + |
| | | // // msg + |
| | | // // "------" + |
| | | // // error.message + |
| | | // // "--反应时间:" + |
| | | // // times(startTime), |
| | | // // type: "error", |
| | | // // duration: 0, |
| | | // // }); |
| | | // Message({ |
| | | // showClose: true, |
| | | // message: "未开启位置权限", |
| | | // type: "error", |
| | | // duration: 2000, |
| | | // }); |
| | | // }; |
| | | // let options = { |
| | | // enableHighAccuracy: true, |
| | | // // timeout: 5000, |
| | | // timeout: Infinity, |
| | | // maximumAge: 0, |
| | | // }; |
| | | // console.log(navigator); |
| | | // console.log(navigator.platform); |
| | | // Message({ |
| | |
| | | // }); |
| | | // console.log(CLLocationManager); |
| | | // return; |
| | | if (navigator.platform === "iPhone") { |
| | | //iphone请求权限 |
| | | // let remoGeo = new RemoGeoLocation(); |
| | | // navigator.geolocation.getCurrentPosition = function () { |
| | | // return remoGeo.getCurrentPosition.apply(remoGeo, arguments); |
| | | // }; |
| | | // navigator.geolocation.watchPosition = function () { |
| | | // return remoGeo.watchPosition.apply(remoGeo, arguments); |
| | | // }; |
| | | // Message({ |
| | | // showClose: true, |
| | | // message: "ipone", |
| | | // type: "error", |
| | | // duration: 0, |
| | | // }); |
| | | // console.log(CLLocationManager); |
| | | // Message({ |
| | | // showClose: true, |
| | | // message: CLLocationManager, |
| | | // type: "error", |
| | | // duration: 0, |
| | | // }); |
| | | // return; |
| | | } |
| | | // if (navigator.platform === "iPhone") { |
| | | // //iphone请求权限 |
| | | // // let remoGeo = new RemoGeoLocation(); |
| | | // // navigator.geolocation.getCurrentPosition = function () { |
| | | // // return remoGeo.getCurrentPosition.apply(remoGeo, arguments); |
| | | // // }; |
| | | // // navigator.geolocation.watchPosition = function () { |
| | | // // return remoGeo.watchPosition.apply(remoGeo, arguments); |
| | | // // }; |
| | | // // Message({ |
| | | // // showClose: true, |
| | | // // message: "ipone", |
| | | // // type: "error", |
| | | // // duration: 0, |
| | | // // }); |
| | | // // console.log(CLLocationManager); |
| | | // // Message({ |
| | | // // showClose: true, |
| | | // // message: CLLocationManager, |
| | | // // type: "error", |
| | | // // duration: 0, |
| | | // // }); |
| | | // // return; |
| | | // } |
| | | // return |
| | | // console.log(BMap); |
| | | //百度定位 |
| | |
| | | // }); |
| | | |
| | | // return; |
| | | //高德定位 |
| | | // //高德定位 |
| | | // AMap.plugin("AMap.Geolocation", function () { |
| | | // var geolocation = new AMap.Geolocation({ |
| | | // // 是否使用高精度定位,默认:true |
| | | // enableHighAccuracy: true, |
| | | // // 设置定位超时时间,默认:无穷大 |
| | | // timeout: 10000, |
| | | // // timeout: 10000, |
| | | // // 定位按钮的停靠位置的偏移量,默认:Pixel(10, 20) |
| | | // // buttonOffset: new AMap.Pixel(10, 20), |
| | | // // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false |
| | |
| | | // console.log("成功返回经纬度信息"); |
| | | // Message({ |
| | | // showClose: true, |
| | | // message: |
| | | // "成功返回经纬度信息" + |
| | | // message: "成功返回经纬度信息" + |
| | | // lon + |
| | | // "_" + |
| | | // lat + |
| | |
| | | // console.log(data); |
| | | // Message({ |
| | | // showClose: true, |
| | | // message: |
| | | // "定位获取失败-msg:" + |
| | | // message: "定位获取失败-msg:" + |
| | | // data.message + |
| | | // "------" + |
| | | // "--反应时间:" + |
| | |
| | | // }); |
| | | // } |
| | | // }); |
| | | window.AMap.plugin('AMap.Geolocation', function () { |
| | | var geolocation = new AMap.Geolocation({ |
| | | enableHighAccuracy: true, //是否使用高精度定位,默认:true |
| | | // timeout: 10000, //超过10秒后停止定位,默认:5s |
| | | // buttonPosition: 'RB', //定位按钮的停靠位置 |
| | | // buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20) |
| | | // zoomToAccuracy: true, //定位成功后是否自动调整地图视野到定位点 |
| | | |
| | | // return; |
| | | }); |
| | | // map.addControl(geolocation); |
| | | geolocation.getCurrentPosition(function (status, result) { |
| | | if (status == 'complete') { |
| | | onComplete(result) |
| | | } else { |
| | | onError(result) |
| | | } |
| | | }); |
| | | }); |
| | | //解析定位结果 |
| | | function onComplete(data) { |
| | | // let lngLat = [data.position.lng, data.position.lat] |
| | | // console.log(position); |
| | | // times(startTime); |
| | | var lat = data.position.lat; |
| | | var lon = data.position.lng; |
| | | // console.log("成功返回经纬度信息"); |
| | | // Message({ |
| | | // showClose: true, |
| | | // message: "成功返回经纬度信息(1)" + |
| | | // lon + |
| | | // "_" + |
| | | // lat + |
| | | // "--反应时间:" + |
| | | // times(startTime), |
| | | // type: "success", |
| | | // duration: 2000, |
| | | // }); |
| | | console.log(lon, lat, "成功"); |
| | | outData([lon, lat]); |
| | | } |
| | | //解析定位错误信息 |
| | | function onError(data) { |
| | | // console.log(data, "see") |
| | | Message({ |
| | | showClose: true, |
| | | message: "未开启位置权限", |
| | | type: "error", |
| | | duration: 2000, |
| | | }); |
| | | } |
| | | |
| | | return; |
| | | state.getSPosition = navigator.geolocation.getCurrentPosition( |
| | | success, |
| | | error, |
| | |
| | | actions: {}, |
| | | }; |
| | | |
| | | export default mobilePosition; |
| | | export default mobilePosition; |