Jul*_*ner 2 javascript openlayers openstreetmap
我试图从Openlayers和OSM的可拖动标记中获取纬度/经度,但我找不到投影转换的好设置,我做错了什么?
这是代码:http://pastie.org/2300321(参见addMarker l140&updateTargets l153)&和一个小的演示测试.
如果您提交地址,则拖动标记,经度和纬度都是错误的.我测试了几个不同的预测,但我不确定我要用什么...
我认为问题在于updateTargets方法内部:
var point = this.feature.geometry;
var pixel = new OpenLayers.Pixel(point.x, point.y);
var coord = this.map.getLonLatFromPixel(pixel).transform(
new OpenLayers.Projection("EPSG:900913"),
new OpenLayers.Projection("EPSG:4326")
);
Run Code Online (Sandbox Code Playgroud)
this.feature.geometry已经在lon/lat坐标中指定,而不是以像素为单位.所以我建议你跳过第二行并直接在几何对象上从OpenStreetMap投影到lon/lat的转换:
var coord = this.feature.geometry.transform(
new OpenLayers.Projection("EPSG:900913"),
new OpenLayers.Projection("EPSG:4326")
);
Run Code Online (Sandbox Code Playgroud)