Openlayer当前位置的纬度和经度

v. *_*osh 2 javascript openlayers openlayers-3

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

Goi*_*Off 6

不确定您要寻找的是什么,但是根据鼠标单击或位置,有几种方法可以延长寿命:

鼠标单击纬度和经度:

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;
});
Run Code Online (Sandbox Code Playgroud)

鼠标移动/定位的纬度和经度:

map.on('pointermove', function(evt) {
    //Same code as in click event
});
Run Code Online (Sandbox Code Playgroud)

不确定“获取当前位置的经度和纬度值”是什么。在您的帖子中意味着