gps實時定位

<template>
  <!-- 運單跟中詳情地圖 -->
  <div style="height:900px;">
    <el-amap vid="amapDemo" :zoom="zoom" :center="[longitudes,latitude]" class="amap-demo">
      <el-amap-marker :position="[longitude,latitude]"></el-amap-marker>
    </el-amap>
  </div>
</template>
<script>
import { nowPhoneGPS, nowBeiDouGPS } from "@/api/gpsMap";
export default {
  data() {
    return {
      zoom: 14,
      longitudes: "1",
      latitudes: "3",
      returnData: [],
      longitude: "2",
      latitude: "7"
    };
  },
  created() {
    if (this.$route.query.grabsingleId) {
      this.getNowPhoneGPS();
    }
    if (this.$route.query.plateNumber) {
      this.getNowBeiDouGPS();
    }
  },
  methods: {
    getNowPhoneGPS() {
      nowPhoneGPS({ grabSingleId: this.$route.query.grabsingleId }).then(
        response => {
          if (response.code === 0) {
            this.returnData = response.data[0];
            if (this.returnData.latitude || this.returnData.longitude) {
              this.longitudes = this.returnData.longitude;
              this.latitude = this.returnData.latitude;
              if (this.longitudes || this.latitude) {
                this.longitude = this.returnData.longitude;
                this.latitude = this.returnData.latitude;
              }
            }
          }else{
              this.$message.error(response.msg)
          }
        }
      );
    },
    getNowBeiDouGPS() {
      nowBeiDouGPS({ plateNumber: "京A99999" }).then(response => {
          if (response.code === 0) {
            this.returnData = response.data[0];
            if (this.returnData.latitude || this.returnData.longitude) {
              this.longitudes = this.returnData.longitude;
              this.latitude = this.returnData.latitude;
              if (this.longitudes || this.latitude) {
                this.longitude = this.returnData.longitude;
                this.latitude = this.returnData.latitude;
              }
            }
          }else{
              this.$message.error(response.msg)
          }
      });
    }
  }
};
</script>
<style>
</style>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章