| | |
| | | } |
| | | } |
| | | |
| | | function handleCurrentLocation() { |
| | | if (!navigator.geolocation) { |
| | | message.warning('当前浏览器不支持定位'); |
| | | return; |
| | | } |
| | | loading.value = true; |
| | | navigator.geolocation.getCurrentPosition( |
| | | async (position) => { |
| | | const [longitude, latitude] = wgs84ToBd09( |
| | | position.coords.longitude, |
| | | position.coords.latitude, |
| | | ); |
| | | await selectBaiduLocation(longitude, latitude); |
| | | loading.value = false; |
| | | }, |
| | | () => { |
| | | message.warning( |
| | | '定位失败,请开启浏览器定位权限(非 localhost 环境需使用 HTTPS)', |
| | | ); |
| | | loading.value = false; |
| | | }, |
| | | { enableHighAccuracy: true, maximumAge: 0, timeout: 15_000 }, |
| | | ); |
| | | } |
| | | |
| | | async function initializeMap() { |
| | | if (!hasMapConfig.value || !mapContainer.value) { |
| | | return; |
| | |
| | | @press-enter="handleSearch" |
| | | /> |
| | | <Button :loading="loading" @click="handleSearch">搜索地址</Button> |
| | | <Button @click="handleCurrentLocation">定位到当前位置</Button> |
| | | </div> |
| | | <div |
| | | ref="mapContainer" |