2017-08-30 103 views

回答

1

不知道,正是你要尋找的,但這裏有幾個方法讓Lat Long網基於鼠標點擊或位置:

鼠標點擊緯度和經度:

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 
}); 

不完全相信「當前位置的獲取經度和緯度的價值。」在你的文章中表示

+0

map.on('click', evt => console.log(evt.coordinate)) ''' – tonio