[OpenLayers-Users] Distance problem
Nicolas Noe
niconoe at ulb.ac.be
Wed Nov 25 06:01:12 EST 2009
Hi everyone,
I have a simple problem, bit I can't figure it. I'm probably missing
something very simple and stupid !
I have an OL map with google background. The projection is EPSG:900913,
so the map unit is meters (right?).
I have a marker layer, on which I add a first marker. Then I ask OL to
compute a second marker 1 kilometer on the east, and display it.
It seems to work, except of my distance problem : if I check with the OL
scaleline, there's 1 KM between both markers (which is correct).
However, if I use the ruler tool of Google Earth, I can see there is
only about 650 meters between these 2 points.
Do you have any idea of where my error is ?
Thanks in advance,
Here is my code :
var BeBounds = new OpenLayers.Bounds(2.5, 49.5, 6.5, 51.5);
function mapInit() {
var map = new OpenLayers.Map('map', {
projection: new OpenLayers.Projection("EPSG:900913"),
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new
OpenLayers.Control.LayerSwitcher({'ascending':false}),
new OpenLayers.Control.Permalink(),
new OpenLayers.Control.ScaleLine(),
new OpenLayers.Control.Permalink('permalink'),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.OverviewMap(),
new OpenLayers.Control.KeyboardDefaults()
]
});
var gsat = new OpenLayers.Layer.Google("Google Hybrid",
{
type: G_HYBRID_MAP,
'sphericalMercator':true,
maxExtent: new
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
/*, numZoomLevels: 20*/ });
var markers = new OpenLayers.Layer.Markers("Markers");
map.addLayer(gsat);
map.addLayer(markers);
// Add a marker
var myPoint = new OpenLayers.LonLat(5.080646954,50.49373471);
var myPointInMeters = myPoint.transform(new
OpenLayers.Projection("EPSG:4326"), map.projection);
var pt2 = myPointInMeters.add(1000,0);
var mymark = new OpenLayers.Marker(myPointInMeters);
var mymark2 = new OpenLayers.Marker(pt2);
markers.addMarker(mymark);
markers.addMarker(mymark2);
map.zoomToExtent(BeBounds.transform(new
OpenLayers.Projection("EPSG:4326"), map.projection));
}
More information about the Users
mailing list