OpenLayers 将坐标调整为 0,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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@Niels 的推荐是正确的。
OpenLayers LonLat 对象需要 (经度, 纬度) - 而不是 (纬度, 经度)。
只需交换经纬度的顺序即可:
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: