OpenLayers 将坐标调整为 0,0

发布于 2024-12-11 01:58:18 字数 511 浏览 1 评论 0原文

坦白说,我是 OpenLayers 的新手。我有一个 WGS84 坐标数据库,已将其加载到数据库中。我已经通过回显纬度和经度验证了这一点。

map = new OpenLayers.Map("map");
var mapnik = new OpenLayers.Layer.OSM();
map.addLayer(mapnik);
map.setCenter(new OpenLayers.LonLat(<?php echo $lat;?>, <?php echo $lon;?>).transform(
   new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
   new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
), 4 /*Zoom level*/);

当放入此处时,会将地图移动到 0,0。谁能帮助或指出我正确的方向?

To be blunt, I'm new to OpenLayers. I have a database of WGS84 coordinates which I've loaded into a database. I've verified that this works by echoing latitudes and longitudes.

map = new OpenLayers.Map("map");
var mapnik = new OpenLayers.Layer.OSM();
map.addLayer(mapnik);
map.setCenter(new OpenLayers.LonLat(<?php echo $lat;?>, <?php echo $lon;?>).transform(
   new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
   new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
), 4 /*Zoom level*/);

When putting into here, it moves the map to 0,0. Can anyone help or point me in the right direction?

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

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

发布评论

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

评论(1

执着的年纪 2024-12-18 01:58:18

@Niels 的推荐是正确的。
OpenLayers LonLat 对象需要 (经度, 纬度) - 而不是 (纬度, 经度)。

只需交换经纬度的顺序即可:

map.setCenter(new OpenLayers.LonLat(<?php echo $lon;?>, <?php echo $lat;?>).transform(
    new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
    new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
), 4);

The commend by @Niels is correct.
The OpenLayers LonLat object expects (longitude, latitude) - not (latitude, longitude).

Just swap the order of your lat and lon:

map.setCenter(new OpenLayers.LonLat(<?php echo $lon;?>, <?php echo $lat;?>).transform(
    new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
    new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
), 4);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文