Enter the address to get the latitude and longitude (no map required)

Foreword
Business requirements: According to the detailed address input by the user, obtain the longitude and latitude of the address and pass it to the backend, but no map is required.

Preparation content
1. Install josnp to solve cross-domain and uneasy transfer reporting cross-domain issues

Excuting an order:

npm install vue-jsonp --save


Add the entry file main.js:

import {VueJsonp} from 'vue-jsonp'
Vue.use(VueJsonp)


Basic usage:

this.$jsonp(地址, 传参参数对象{} ).then(json => {
  // 返回的内容
    console.log(json)
}).catch(err => {
  console.log(err)
})


2. Baidu map ak (key), how to apply for Baidu, no explanation

Baidu Map API used, link address:

Reverse geocoding gc | Baidu Map API SDK

Projects and pieces used

this.$jsonp('http://api.map.baidu.com/geocoding/v3/', {
  address: '北京市海淀区上地十街10号',
  output: 'json',
  ak: 您的密钥
}).then(json => {
   // 得到我们想要的内容
   console.log(json)
}).catch(err => {
   console.log(err)
})

Guess you like

Origin blog.csdn.net/qq_42676363/article/details/123733737