gpt4 book ai didi

javascript - openlayer中当前位置的经纬度

转载 作者:行者123 更新时间:2023-12-04 01:30:18 25 4
gpt4 key购买 nike

我正在尝试获取当前位置的纬度和经度值。有什么方法可以获得经纬度值吗?我试图通过获取当前位置的纬度和经度值来放置制造商。

最佳答案

不确定您正在寻找什么,但这里有几种方法可以根据鼠标单击或位置获得经纬度:

鼠标单击经纬度:

map.on('click', function(evt){
console.info(evt.pixel);
console.info(map.getPixelFromCoordinate(evt.coordinate));
console.info(ol.proj.toLonLat(evt.coordinate));
var coords = ol.proj.toLonLat(evt.coordinate);
var lat = coords[1];
var lon = coords[0];
var locTxt = "Latitude: " + lat + " Longitude: " + lon;
// coords is a div in HTML below the map to display
document.getElementById('coords').innerHTML = locTxt;
});

鼠标移动/定位经纬度:
map.on('pointermove', function(evt) {
//Same code as in click event
});

不完全确定“获取当前位置的纬度和经度值”是什么。意思是在你的帖子里

关于javascript - openlayer中当前位置的经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45958565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com