提交 99086111 authored 作者: 钟是志's avatar 钟是志

组件错误

上级 8fa645e9
...@@ -10,9 +10,10 @@ export default function getLocation(callBack = () => {}){ ...@@ -10,9 +10,10 @@ export default function getLocation(callBack = () => {}){
const point = new BMap.Point(107.303748,34.346725); const point = new BMap.Point(107.303748,34.346725);
map.centerAndZoom(point, 11); map.centerAndZoom(point, 11);
const geolocation = new BMap.Geolocation(); const geolocation = new BMap.Geolocation();
geolocation.enableSDKLocation();
geolocation.getCurrentPosition(function(r){ geolocation.getCurrentPosition(function(r){
if(this.getStatus() === 0) { if(this.getStatus() === 0) {
let address = getAddress(r.point); let address = getAddress(r.point, callBack);
let mk = new BMap.Marker(r.point); let mk = new BMap.Marker(r.point);
map.addOverlay(mk); map.addOverlay(mk);
map.panTo(r.point); map.panTo(r.point);
...@@ -24,45 +25,18 @@ export default function getLocation(callBack = () => {}){ ...@@ -24,45 +25,18 @@ export default function getLocation(callBack = () => {}){
} }
},{enableHighAccuracy: true}); },{enableHighAccuracy: true});
// 通过坐标 拿取地址名字 }
function getAddress(point) {
export function getAddress(point, callBack=()=>{}){
const lng = point.lng; // 经度 const lng = point.lng; // 经度
const lat = point.lat; // 纬度 const lat = point.lat; // 纬度
let gc = new BMap.Geocoder(); let gc = new BMap.Geocoder();
gc.getLocation(point,function(res){ gc.getLocation(point,function(res){
let formValues = {}; let formValues = {};
let status = 0;
// 判断范围
const zoneCaculate = (origin,r) => {
let currR = Math.sqrt(Math.pow(origin.lng - lng,2) + Math.pow(origin.lat - lat,2))
if(currR <= r) {
return 1;
}else{
return 0
}
};
// 判断时间
const caculateTime = (startTime, endTime) => {
let currTime = new Date().getTime();
if(startTime < currTime && currTime < endTime) {
return 1;
}else{
return 0;
}
};
// 处理状态
const isZone = zoneCaculate({lng: 104, lat: 30},1000);
const isTime = caculateTime(new Date().getTime() - 10000,new Date().getTime() + 10000);
if(isZone === 0) status = 0;
if(isZone === 1 && isTime === 1) status = 2;
if(isZone === 1 && isTime === 0) status = 1;
// 更改状态 // 更改状态
formValues.address = res.address; formValues.address = res.address;
formValues.lng = lng; formValues.lng = lng;
formValues.lat = lat; formValues.lat = lat;
callBack(formValues); callBack(formValues);
}); });
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论