| | |
| | | <image src="/static/location/back.png" class="w-19 h-35" mode=""></image> |
| | | </view> |
| | | </u-navbar> |
| | | <view class="" id="container" @regionchange="onRegionChange"> |
| | | <view class="" id="container"> |
| | | |
| | | </view> |
| | | <view class=" main"> |
| | |
| | | }; |
| | | }, |
| | | methods: { |
| | | |
| | | back() { |
| | | uni.navigateBack() |
| | | }, |
| | | onRegionChange(e) { |
| | | if (e.type === 'end') { |
| | | // 地图移动结束时执行操作 |
| | | console.log('地图移动结束,新的中心点经度:', e.longitude, '新的中心点纬度:', e.latitude); |
| | | } |
| | | }, |
| | | |
| | | changeAdr(value, addr) { |
| | | console.log(value, addr, 'asdasdada'); |
| | | this.uid = value |
| | | const pages = getCurrentPages() |
| | | let prevPage = pages[pages.length - 2]; |
| | | prevPage.location = addr.address |
| | | prevPage.latitude = addr.point.lat |
| | | prevPage.longitude = addr.point.lng |
| | | setTimeout(() => { |
| | | uni.navigateBack() |
| | | }, 500) |
| | | }, 200) |
| | | }, |
| | | // 搜索地点 |
| | | searchLocation() { |
| | |
| | | method: 'GET', |
| | | data: { |
| | | query: this.keyword, |
| | | location: `${30.39},${104.04}`, |
| | | location: `${this.latitude},${this.longitude }`, |
| | | radius: 10000, // 搜索半径,单位:米 |
| | | output: 'json', |
| | | ak: '3mHKIXMArjgIkgADzOlTYp4XssNSNkwr' // 替换为你自己的 AK |
| | |
| | | }, |
| | | onReady() { |
| | | this.map = new BMapGL.Map("container"); // 创建地图实例 |
| | | |
| | | |
| | | uni.getLocation({ |
| | | type: 'wgs84', |
| | | success: (res) => { |
| | |
| | | this.longitude = res.longitude; |
| | | this.latitude = res.latitude; |
| | | var point = new BMapGL.Point(res.longitude, res.latitude); // 创建点坐标 |
| | | this.map.enableScrollWheelZoom(true); |
| | | this.map.centerAndZoom(point, 12); |
| | | var marker = new BMapGL.Marker(point); |
| | | this.map.addOverlay(marker); |
| | | var myGeo = new BMapGL.Geocoder(); |
| | | // 根据坐标得到地址描述 |
| | | myGeo.getLocation(new BMapGL.Point(res.longitude, res.latitude), (result) => { |
| | |
| | | }) |
| | | |
| | | }) |
| | | this.map.addEventListener('click', (e) => { |
| | | var mercator = this.map.lnglatToMercator(e.latlng.lng, e.latlng.lat); |
| | | this.latitude = e.latlng.lat |
| | | this.longitude = e.latlng.lng |
| | | var point = new BMapGL.Point(e.latlng.lng, e.latlng.lat); |
| | | this.map.centerAndZoom(point, 12); |
| | | var myGeo = new BMapGL.Geocoder(); |
| | | // 根据坐标得到地址描述 |
| | | myGeo.getLocation(new BMapGL.Point(e.latlng.lng, e.latlng.lat), (result) => { |
| | | console.log(result, 'result'); |
| | | this.locationList = result.surroundingPois.map((item, index) => { |
| | | item.id = index + 1 |
| | | return item |
| | | }) |
| | | |
| | | }) |
| | | var marker = new BMapGL.Marker(point); |
| | | this.map.addOverlay(marker); |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | </script> |