美文网首页
其他坐标转成高德坐标

其他坐标转成高德坐标

作者: 张星的 | 来源:发表于2018-12-19 10:19 被阅读0次

index.html文件

<!DOCTYPE html>

<html>

  <head>

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width,initial-scale=1.0">

    <title>gaode</title>

    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.8&key=b7fa33338e17e5e654cbb593342bf038"></script>

    <script src="//webapi.amap.com/ui/1.0/main.js"></script>

  </head>

  <body>

    <div id="app"></div>

    <!-- built files will be auto injected -->

  </body>

</html>

坐标转化gps-gaode文件:

<template>

  <div id="container" class="myarea">

    <button @click="getLonDim()">转换</button>

    <div class="code"></div>

  </div>

</template>

<script>

  const gpsList =[

    {"FID":"2416","x":"121.056818","y":"30.599973",},

    {"FID":"2417","x":"121.056826","y":"30.599974",},

    {"FID":"2418","x":"121.056951","y":"30.599992",},

    {"FID":"2419","x":"121.056953","y":"30.599992",}

  ];

  import AMap from 'AMap';

  export default {

    name: "gps-gaode",

    data() {

      return {

        list: gpsList,

        gps: [],

        gaode: []

      }

    },

    components: {

      AMap

    },

    // mounted() {

    //  this.getLonDim();

    // },

    methods: {

      getLonDim() {

        let x,y;

        let $this = this;

        $this.list.forEach(function(e){

          x = e.x;

          y = e.y;

          $this.gps.push(x, y);

          AMap.convertFrom($this.gps, 'gps', function (status, result) {

            if (result.info === 'ok') {

              var lnglats = result.locations;

              $this.gaode.push('['+lnglats["0"].O+','+lnglats["0"].P+']');

              console.log('['+lnglats["0"].P+','+lnglats["0"].O+']'+',')

              // console.log(lnglats["0"].P)

            } else {

              console.log('你是' + result.info)

            }

          });

            $this.gps = [];

        })

      }

    }

  }

</script>

<style scoped>

  .myarea {

    width: 100%;

    height: 100%;

  }

</style>

相关文章