|
@@ -1,57 +0,0 @@
|
|
-import AMapLoader from '@amap/amap-jsapi-loader';
|
|
|
|
-import $config from "@/config/index.js"
|
|
|
|
-
|
|
|
|
-export const getCoord = (parmas) => {
|
|
|
|
- return new Promise((reslove, reject) => {
|
|
|
|
- const { name, code, type } = parmas;
|
|
|
|
- window._AMapSecurityConfig = {
|
|
|
|
- securityJsCode: $config.secretKey,
|
|
|
|
- };
|
|
|
|
- // 配置高德API的key
|
|
|
|
- AMapLoader.load({
|
|
|
|
- "key": $config.key,
|
|
|
|
- "version": "2.0",
|
|
|
|
- "plugins": []
|
|
|
|
- })
|
|
|
|
- .then((AMap) => {
|
|
|
|
- AMap.plugin('AMap.Geocoder', function() {
|
|
|
|
- var geocoder = new AMap.Geocoder({
|
|
|
|
- city: code // city 指定进行编码查询的城市,支持传入城市名、adcode 和 citycode
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- var addresses = [name];
|
|
|
|
- // 使用高德逆编码,将天地图转换成高德地图
|
|
|
|
- geocoder.getLocation(addresses, function(status, result) {
|
|
|
|
- if (status === 'complete' && result.info === 'OK') {
|
|
|
|
- const val = result.geocodes[0];
|
|
|
|
- reslove(val.location)
|
|
|
|
- }else{
|
|
|
|
- reject()
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // var gps = [longitude, latitude]; //需要转换的gps类型的坐标
|
|
|
|
- // // var gps = [116.3, 39.9]; //需要转换的gps类型的坐标
|
|
|
|
- // // 初始化地图实例
|
|
|
|
- // console.log('AMap =', AMap, gps)
|
|
|
|
- // // window.map = new AMap.Map('container', {
|
|
|
|
- // // zoom: 10, // 设置地图显示的缩放级别
|
|
|
|
- // // center: [116.397428, 39.90923] // 设置地图中心点坐标
|
|
|
|
- // // });
|
|
|
|
- // //参数说明:需要转换的坐标或者坐标组,需要转换的坐标类型,转换成功后的回调函数
|
|
|
|
- // AMap.convertFrom(gps, "gps", function(status, result) {
|
|
|
|
- // console.log('status, result =', status, result)
|
|
|
|
- // //status:complete 表示查询成功,no_data 为查询无结果,error 代表查询错误
|
|
|
|
- // //查询成功时,result.locations 即为转换后的高德坐标系
|
|
|
|
- // if (status === "complete" && result.info === "ok") {
|
|
|
|
- // var lnglats = result.locations; //转换后的高德坐标 Array.<LngLat>
|
|
|
|
- // console.log(lnglats);
|
|
|
|
- // }
|
|
|
|
- // });
|
|
|
|
- })
|
|
|
|
- .catch(e => {
|
|
|
|
- reject()
|
|
|
|
- });
|
|
|
|
- })
|
|
|
|
-}
|
|
|