var state = { // 1:click—map 2:select-map input_state: 1, list_state: 1 } window.onload = function load() { document.getElementById("searchDiv").innerHTML = ""; document.getElementById("resultDiv").style.display = "none"; const init = new Promise((resolve, reject) => { if(T) { console.log('地图初始化成功') resolve(T) reject('error') } }) init.then(T => { map = new T.Map('map'); center = new T.LngLat(113.214781,23.406641); map.centerAndZoom(center, 15); 请修改为: 默认设置地图中心点为(113.214781,23.406641),通过点击一个按钮实现获取当前位置并设置为地图中心点后的代码
时间: 2024-04-27 13:23:19 浏览: 11
var state = { // 1:click—map 2:select-map input_state: 1, list_state: 1 }
window.onload = function load() {
document.getElementById("searchDiv").innerHTML = "";
document.getElementById("resultDiv").style.display = "none";
const center = new T.LngLat(113.214781,23.406641);
map = new T.Map('map');
map.centerAndZoom(center, 15);
}
function setCurrentLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
const { latitude, longitude } = position.coords;
const center = new T.LngLat(longitude, latitude);
map.centerAndZoom(center, 15);
});
} else {
console.log('Geolocation is not supported by this browser.');
}
}
请将按钮的HTML代码添加到页面中,例如:<button onclick="setCurrentLocation()">获取当前位置</button>。同时,确保在页面中正确引入了Tencent地图的JavaScript SDK。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)