Explorar o código

feat: 使用fetch调试高德地图接口

zhaolianxi %!s(int64=3) %!d(string=hai) anos
pai
achega
f1d79167e4
Modificáronse 6 ficheiros con 41 adicións e 14 borrados
  1. 1 1
      index.html
  2. 1 1
      src/components/Home.vue
  3. 36 12
      src/components/orderComponents/orderAMap.vue
  4. 3 0
      src/main.js
  5. BIN=BIN
      static/image/map-fa.png
  6. BIN=BIN
      static/image/map-shou.png

+ 1 - 1
index.html

@@ -3,7 +3,7 @@
   <head>
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
-    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=610161977d2e2632eb34aff3e88a079f"></script>
+    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=5ae8644771ef9abf9cfb3ea23b1df6ca"></script>
     <title>猎豹AI</title>
   </head>
   <body>

+ 1 - 1
src/components/Home.vue

@@ -36,7 +36,7 @@
         </div>
       </el-col>
     </el-row>
-    <!-- <order-map></order-map> -->
+    <order-map></order-map>
   </div>
 </template>
 

+ 36 - 12
src/components/orderComponents/orderAMap.vue

@@ -1,9 +1,11 @@
 <template>
   <el-dialog width="80%" :show-close="false" destroy-on-close :visible.sync="dialogTableVisible">
     <!-- <div id="container"></div> -->
+    <div>
+      <el-input v-model="searchKey" @change="searchMap($event)"/>
+    </div>
     <el-amap vid="container" style="height: 600px;" :center="center" :zoom="zoom" class="amap-demo">
-      <!-- <el-amap-marker v-for="(marker,index) in markers" :key="index" :position="marker.position"
-        :events="marker.events"></el-amap-marker> -->
+      <el-amap-marker v-for="(marker,index) in markers" :key="index" :position="marker.position" :icon="marker.icon"></el-amap-marker>
       <!-- <el-amap-info-window v-if="window" :position="window.position" :visible="window.visible"
         :content="window.content"></el-amap-info-window> -->
     </el-amap>
@@ -11,19 +13,25 @@
 </template>
 
 <script>
+  import qs from 'qs';
+  //var map = new AMap.Map('container');
   export default {
     data() {
       return {
+        searchKey: '',
         dialogTableVisible: true,
         order: {},
-        markers: [],
+        markers: [
+          { id:1, position: [120.629585, 31.269379], icon: '/static/image/map-fa.png' },
+          { id:2, position: [120.609585, 31.209379], icon: '/static/image/map-shou.png' },
+        ],
         srcList: [],
         windows: [],
         window: '',
         geocoder: '',
         defaultCity: '苏州',
-        zoom: 16,
-        center: [120.619585, 31.299379],
+        zoom: 12,
+        center: [120.619585, 31.239379],
         address: '',
         province: '',
         city: '',
@@ -35,14 +43,25 @@
         },
       }
     },
-    created() {
-      var map = new AMap.Map('container', {
-        zoom: 11, //级别
-        center: [116.397428, 39.90923], //中心点坐标
-      });
-      console.log(map, '地图')
-    },
+    created() {},
     methods: {
+      searchMap(e) {
+        console.log(e)
+        fetch('https://restapi.amap.com/v3/assistant/inputtips?key=5ae8644771ef9abf9cfb3ea23b1df6ca&keywords=苏州大学&city=0512&offset=20&types=keywords',{
+          methods: 'GET'
+        }).then( res => {
+          return res.json()
+        }).then( result => {
+          console.log(result);
+          fetch(`https://restapi.amap.com/v3/geocode/geo?key=4940f0a9fdc717ab27dd37fa0497c771&address=${ result.tips[0].district }${ result.tips[0].address }${ result.tips[0].name }`,{
+            methods: 'GET'
+          }).then( res1 => {
+            return res1.json()
+          }).then( rp => {
+            console.log(rp, '------------')
+          } )
+        } )
+      },
       setDialogStatus() {
         this.dialogTableVisible = true;
       }
@@ -51,6 +70,7 @@
 </script>
 
 <style lang="scss" scoped>
+  /* 图标大小修改 */
   /deep/ .el-dialog__header {
     display: none !important;
   }
@@ -58,4 +78,8 @@
     width: 100%;
     height: 400px;
   }
+  /deep/ .amap-container img {
+    width: 35px !important;
+    height: 45px !important;
+  }
 </style>

+ 3 - 0
src/main.js

@@ -7,6 +7,9 @@ import router from './router'
 import Elementui from 'element-ui'
 import store from './store/index.js';
 
+import axios from 'axios'
+Vue.prototype.$axios = axios    //全局注册,使用方法为:this.$axios
+
 import VueAMap from 'vue-amap';
 
 import {get, post, postJson} from './api/http'

BIN=BIN
static/image/map-fa.png


BIN=BIN
static/image/map-shou.png