Oh, there is a mistake in the example. I fixed it yet.
http://jsfiddle.net/3pPB3/2/
In fact, what I said about the marker located at a wrong place is not
related to the initializate location of the marker.
You may notice this function in my script:
* map.events.register("click", map, function(evt) {
var pos = map.getLonLatFromPixel(evt.xy);
updateMaker(myMarker, pos);
});
function updateMaker(myMarker, pos) {
myMarker.moveTo(myMarker.map.getPixelFromLonLat(pos));
}*
As you can see, once I click on the map, I want the marker's position
updated and re-located.
Everything goes well if you do not move the map, but once you drag the map
, the then click the map, you will find that the marker is located at a
wrong place rather than the position where the mouse resides.
.
2013/5/31 Mario Danelli <[email protected]>
> Dear Maven,
>
> > Once you move the map, the marker will be located at the wrong place,
> why?
>
> As I see from your example, the marker is located in a wrong position at
> start-up. It's placed near LAT 0 and LON 0.
>
> You should use the TRANSFORM method to change from projection WGS 1984
> (tipically used) to projection Mercator (used in OpenStreetMap tiles). See
> the following code for a brief presentation:
>
>
> ------------------> BEGIN
>
> // transform from WGS 1984
> var fromProjection = new OpenLayers.Projection("EPSG:4326");
>
> // to Spherical Mercator Projection
> var toProjection = new OpenLayers.Projection("EPSG:900913");
>
> new OpenLayers.LonLat(YOUR_MARKER_LON, YOUR_MARKER_LAT)
> .transform(fromProjection, toProjection);
>
> <------------------ END
>
> Regards
>
> Mario Danelli
>
> _______________________________________________
> Users mailing list
> [email protected]
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users