[OpenLayers-Users] OpenLayers with Google Maps - how to obtain degree lat/long?

plen peteralen at earthlink.net
Tue Nov 17 15:50:35 EST 2009


Eric,

The transform function indeed seemed to work.  My Point now is listed in
decimal lat/lon.  I though that would solve my problem but it looks like
something else is not working.  When I use that new transformed Point to add
an icon to the map, the icon gets added to the 0,0 location regardless of
that the Point's lat/long value is.  It seems like the internal API code is
having problems dealing with the transformed value and doesn't know how to
place it on the map using a lat/lon, so it simply places it at 0,0.

-------------------------------
var lonlat = map.getLonLatFromViewPortPx(e.xy);
var point = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
point.transform(
    new OpenLayers.Projection("EPSG:900913"),
    new OpenLayers.Projection("EPSG:4326")
);

var iconSize =  new OpenLayers.Size(16, 16);
var iconURL = MY_ICON;
var iconOffset = new OpenLayers.Pixel(8,8);
var marker = new OpenLayers.Marker(
                new OpenLayers.LonLat(point.x, point.y),
                new OpenLayers.Icon(iconURL,iconSize,iconOffset));
getMarkersLayer().addMarker(marker);
--------------------------------

The same also happens if I created a OpenLayers.Feature.Vector type of
point.

So, while the transform function allowed me to get the location as a decimal
lat/lon, it doesn't appear that I can use that value to add a map icon to
that location.  Is there some additional transformation that needs to occur. 
It would seem that this would be a common thing to do.

Any new thoughts as to what I am missing?

Thanks as always - Peter

-- 
View this message in context: http://n2.nabble.com/OpenLayers-with-Google-Maps-how-to-obtain-degree-lat-long-tp4016339p4021195.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list