| | |
| | | result.id = index + 1 |
| | | return result |
| | | }); |
| | | |
| | | |
| | | } |
| | | }) |
| | | return |
| | |
| | | ak: '3mHKIXMArjgIkgADzOlTYp4XssNSNkwr' // 替换为你自己的 AK |
| | | }, |
| | | success: (res) => { |
| | | |
| | | |
| | | if (res.data.status === 0) { |
| | | this.searchResults = res.data.results; |
| | | this.latitude = res.data.results[0].location.lat |
| | |
| | | }, |
| | | onReady() { |
| | | this.map = new BMapGL.Map("container"); // 创建地图实例 |
| | | |
| | | |
| | | // uni.getLocation({ |
| | | // type: 'wgs84', |
| | | // success: (res) => { |
| | | navigator.geolocation.getCurrentPosition(success, error, options); |
| | | |
| | | function success(position) { |
| | | let that = this |
| | | const latitude = position.coords.latitude; |
| | | const longitude = position.coords.longitude; |
| | | const accuracy = position.coords.accuracy; // 精度,单位米 |
| | | |
| | | |
| | | that.latitude = latitude |
| | | that.latitude = latitude |
| | | // 在这里可以使用获取到的经纬度信息,例如在地图上显示位置等。 |
| | | } |
| | | |
| | | function error(err) { |
| | | |
| | | |
| | | switch (err.code) { |
| | | case err.PERMISSION_DENIED: |
| | | console.error("用户拒绝了位置请求。"); |
| | |
| | | timeout: 5000, // 5 秒超时 |
| | | maximumAge: 0 // 不使用缓存 |
| | | }; |
| | | let res = { |
| | | longitude: 101.725544, |
| | | latitude: 26.587259 |
| | | } |
| | | // let res = { |
| | | // longitude: 101.725544, |
| | | // latitude: 26.587259 |
| | | // } |
| | | this.longitude = res.longitude; |
| | | this.latitude = res.latitude; |
| | | var point = new BMapGL.Point(res.longitude, res.latitude); // 创建点坐标 |
| | |
| | | item.id = index + 1 |
| | | return item |
| | | }) |
| | | |
| | | |
| | | }) |
| | | this.map.addEventListener('click', (e) => { |
| | | this.clearMarkers() |
| | |
| | | var myGeo = new BMapGL.Geocoder(); |
| | | // 根据坐标得到地址描述 |
| | | myGeo.getLocation(new BMapGL.Point(e.latlng.lng, e.latlng.lat), (result) => { |
| | | |
| | | |
| | | this.locationList = result.surroundingPois.map((item, index) => { |
| | | item.id = index + 1 |
| | | return item |