| | |
| | |
|
| | | <script>
|
| | | import {
|
| | | searchLocation
|
| | | searchLocation,
|
| | | geoconv
|
| | | } from './service'
|
| | | export default {
|
| | | data() {
|
| | |
| | | navigator.geolocation.getCurrentPosition(success, error, options);
|
| | |
|
| | | function success(position) {
|
| | | uni.request({
|
| | | url: `https://api.map.baidu.com/geoconv/v2/?coords=${position.coords.longitude},${position.coords.latitude}&model=2&ak=3mHKIXMArjgIkgADzOlTYp4XssNSNkwr`,
|
| | | method: 'GET',
|
| | | success: (res) => {
|
| | | const latitude = res.data.result[0].y;
|
| | | const longitude = res.data.result[0].x;
|
| | | var point = new BMapGL.Point(longitude, latitude); // 创建点坐标
|
| | | that.map.enableScrollWheelZoom(true);
|
| | | that.map.centerAndZoom(point, 12);
|
| | | var marker = new BMapGL.Marker(point);
|
| | | that.map.addOverlay(marker);
|
| | | that.markers.push(marker);
|
| | | var myGeo = new BMapGL.Geocoder();
|
| | | // 根据坐标得到地址描述 |
| | | myGeo.getLocation(new BMapGL.Point(longitude, latitude), (result) => {
|
| | | that.locationList = result.surroundingPois.map((item, index) => {
|
| | | item.id = index + 1
|
| | | return item
|
| | | })
|
| | | geoconv({coords:`${position.coords.longitude},${position.coords.latitude}`}).then(res=>{
|
| | | const latitude = res.data[0].y;
|
| | | const longitude = res.data[0].x;
|
| | | that.map.enableScrollWheelZoom(true);
|
| | | that.map.centerAndZoom(point, 12);
|
| | | var marker = new BMapGL.Marker(point);
|
| | | that.map.addOverlay(marker);
|
| | | that.markers.push(marker);
|
| | | var myGeo = new BMapGL.Geocoder();
|
| | | // 根据坐标得到地址描述 |
| | | myGeo.getLocation(new BMapGL.Point(longitude, latitude), (result) => {
|
| | | that.locationList = result.surroundingPois.map((item, index) => {
|
| | | item.id = index + 1
|
| | | return item
|
| | | })
|
| | | },
|
| | | });
|
| | | })
|
| | | })
|
| | | }
|
| | |
|
| | | function error(err) {
|