如何获得lat&lon(从map. getcenter())值在每个地图'move'(平移,缩放&out

How to get the lat&lon (from map.getCenter()) values on each map 'move'(pan,zoomin&out)?

本文关键字:地图 move 平移 out 缩放 lon lat 何获得 map getcenter      更新时间:2023-09-26

我使用eclipse luna创建了一个'动态java项目'(java7),并使用geoserver成功渲染了postgis-postgresql数据库中的地图&openlayers - 2.13。现在我想要得到纬度&每次地图移动时中心点的经度值,以便我可以打印具有当前位置的地图。我的代码是:

var map = new OpenLayers.Map("map");
var layer  = new OpenLayers.Layer.WMS( "District Boundary","http://localhost:8080/geoserver/gwc/service/wms/sde", {layers: 'sde:district_boundary' } );
map.addLayer([layer]);
map.setCenter(new OpenLayers.LonLat(76.452, 10.528), 7);
map.events.register("move", map, function() {
    console.debug('lat : '+map.getCenter().lat());
});

但是我得到这样的错误TypeError: map.getCenter(…)。lat不是函数

错误信息是明确的:lat是一个属性,而不是一个函数,所以你不应该通过p.lat()调用它,而是通过p.lat

而且,错误信息表明你没有发布你正在真正运行的代码——不要这样做,因为它可能使调查你的问题变得不可能。