a.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // 引入高德地图JSAPI(请确保已经在项目中引入了高德地图JSAPI)
  2. const AMap = require('@amap-jsapi-biz/src/amap-wx');
  3. export default {
  4. data() {
  5. return {
  6. // 假设这是从天地图获取的坐标点
  7. tianDiTuCoord: [116.397428, 39.90923], // 天地图坐标点, 经度, 纬度
  8. };
  9. },
  10. methods: {
  11. convertCoord() {
  12. // 初始化高德地图JSAPI
  13. new AMap.AMapWX({
  14. key: '你的高德地图Web服务API Key', // 替换为你的高德地图Web服务API Key
  15. });
  16. // 调用坐标转换服务
  17. AMap.convertFrom({
  18. coordType: 'wgs84', // 坐标类型,可选值:'gcj02', 'bd09', 'bd09ll', 'wgs84', 'google', 'sogou', 'mapbar', 'geocoder', 'auto', 'mars', 'openstreetmap', 'tianjd'
  19. locations: this.tianDiTuCoord, // 待转换坐标数组
  20. }).then((data) => {
  21. // 转换成功,data.locations为转换后的坐标数组
  22. console.log('转换后的坐标:', data.locations);
  23. }).catch((err) => {
  24. // 转换失败的处理逻辑
  25. console.error('坐标转换失败:', err);
  26. });
  27. },
  28. },
  29. onLoad() {
  30. this.convertCoord();
  31. },
  32. };