[英]Openlayers - Getting Incorrect LonLat while transform?
I have trying to get Latitude
and Longitude
of a Point. 我试图获得一个点的Latitude
和Longitude
。 But While transforming it's not returning the correct LonLat
. 但是,在进行转换时,它不会返回正确的LonLat
。 It's big number that is not a lonlat
point for sure. 这是很大的数字,是不是lonlat
肯定的点。
I have tried for some solutions but didn't get result. 我已经尝试了一些解决方案,但没有得到结果。 What else could be failing? 还有什么可能会失败?
JS Code I have Tried 我尝试过的JS代码
map = createMap("deviceMap");
var fromProjection = new OpenLayers.Projection("EPSG:4326");
var toProjection = new OpenLayers.Projection("EPSG:900913");
map.events.register('click', map, function handleMapClick(e) {
lonLat = self.map.getLonLatFromViewPortPx(e.xy).
transform(map.getProjectionObject(), toProjection);
prompt("",lonLat);
});
Finally got answer 终于得到答案
map.events.register('click', map, function handleMapClick(e) {
var toProjection = new OpenLayers.Projection("EPSG:4326");
var lonLat = map.getLonLatFromPixel(e.xy).
transform(map.getProjectionObject(), toProjection);
});
If I understand you right, you should have in variable lonLat a high number. 如果我没看错,您应该在变量lonLat中增加一个大数字。
"LonLat" in OpenLayers does not mean, it will be only longitude/latitude, see documentation here : OpenLayers中的“ LonLat”并不意味着它只是经度/纬度,请参阅此处的文档:
lon {Number} The x-axis coordinate in map units. lon {Number}以地图单位表示的x轴坐标。 If your map is in a geographic projection, this will be the Longitude. 如果您的地图在地理投影中,则为经度。 Otherwise, it will be the x coordinate of the map location in your map units. 否则,它将是地图单位中地图位置的x坐标。
lat {Number} The y-axis coordinate in map units. lat {Number}以地图为单位的y轴坐标。 If your map is in a geographic projection, this will be the Latitude. 如果您的地图在地理投影中,则为纬度。 Otherwise, it will be the y coordinate of the map location in your map units. 否则,它将是地图单位中地图位置的y坐标。
So if you want to get a real LonLat coordinates, you should not convert it (and use EPSG:4326) or convert it to the other coordinate system, not EPSG:900913. 因此,如果要获取真实的LonLat坐标,则不应转换(并使用EPSG:4326)或将其转换为其他坐标系,而不是EPSG:900913。
By the way, OpenLayers started to use 900918 (numeric equivalent to GOOGlE), It was define by Mr. Christopher Schmidt , firstly it was not accepted by European Petroleum Survey Group (EPSG). 顺便说一下,OpenLayers开始使用900918(相当于GOOGlE的数字),由Christopher Schmidt先生定义,首先,它未被欧洲石油测量集团(EPSG)接受。 Then EPSG changed their mind and gave them number: 3857 - WGS84 Pseudo-Mercator. 然后EPSG改变了主意,给了他们号码:3857-WGS84伪墨卡托。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.