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

定位地址修改

上级 06fc9c30
import React, { useState, useEffect } from 'react';
import getLocation from '@/H5Public/utils/handleLocation';
export default function Test() {
const [location, setLocation] = useState({});
......@@ -10,11 +9,11 @@ export default function Test() {
};
useEffect(()=>{
getLocation(setInfo)
getLocation(setInfo);
},[])
return (
<div id={'baiduMap'}>
<div id="baiduMap">
{JSON.stringify(location)}
</div>
);
......
......@@ -2,22 +2,17 @@ const isHttps = window.location.protocol.indexOf('https') > -1;
const apiVersion = isHttps ? '3.0' : '2.0';
const mapContaienrId = "baiduMap";
const apiSrc = `https://api.map.baidu.com/api?v=${apiVersion}&ak=WPau2m9l3Rty2HR7Kfc9879nzP2Fj0UU&callback=baiduMapInitialize`;
const hasMapContainer = !!document.getElementById(mapContaienrId);
function loadScript(callBack) {
window.baiduMapInitialize = function () {
getLocationByMap(callBack);
}
if (!hasMapContainer) {
document.write(`
<div id="${mapContaienrId}"></div>
`);
}
document.write(`<script type="text/javascript" src="${apiSrc}"></script>`);
}
function getLocationByMap(callback) {
const BMap = window.BMap;
//
const map = new BMap.Map(mapContaienrId);
const point = new BMap.Point(107.303748,34.346725);
map.centerAndZoom(point, 12);
......@@ -93,8 +88,9 @@ export default function getLocation(callBack = () => {}){
if(typeof BMap === 'undefined') {
loadScript(callBack);
return false;
}else{
getLocationByMap(callBack);
}
getLocationByMap(callBack);
}
export function getAddress(point, callBack=()=>{}){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论