Openlayers - 从某个点获取纬度/经度时的投影问题

发布于 2024-11-27 11:14:16 字数 353 浏览 3 评论 0原文

我正在尝试使用 Openlayers 和 OSM 从可拖动标记获取纬度/经度,但我找不到投影转换的良好设置,我做错了什么?

这是代码: http://pastie.org/2300321 (请参阅 addMarker l140 和 updateTargets l153)和和一些演示测试

如果您提交地址,然后拖动标记,则经度和纬度是错误的。我测试了一些不同的投影,但我不确定我必须使用什么......

I'm trying to get the latitude/longitude from a draggable marker with Openlayers and OSM but I can't find the good settings for the projection conversion, what I am doing wrong ?

Here is the code: http://pastie.org/2300321 (see addMarker l140 & updateTargets l153) & and a little demo test.

If you submit an address, then drag the marker, the longitude and latitude are wrong. I tested a few different projections but I'm not sure what I've to use…

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉城 2024-12-04 11:14:16

我认为问题出在 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")
);

this.feature.geometry 已经在 lon/lat 坐标中指定,而不是在像素中。因此,我建议您跳过第二行,直接在几何对象上将 OpenStreetMap 投影转换为 lon/lat:

var coord = this.feature.geometry.transform(
   new OpenLayers.Projection("EPSG:900913"),
   new OpenLayers.Projection("EPSG:4326")
);

I think the problem is inside updateTargets method:

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

this.feature.geometry is already specified in lon/lat coordinates, not in pixels. So I suggest that you skip second line and do the conversion from OpenStreetMap projection to lon/lat directly on geometry object:

var coord = this.feature.geometry.transform(
   new OpenLayers.Projection("EPSG:900913"),
   new OpenLayers.Projection("EPSG:4326")
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文