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

plen peteralen at earthlink.net
Mon Nov 16 22:16:01 EST 2009


Hello,

I am using OpenLayers 2.8 and based on multiple examples I found, I use the
following to load a Google Map map layer:

------------------------------
var options = {
                projection: new OpenLayers.Projection("EPSG:900913"),
                units: "m",
                maxResolution: 156543.0339,
                maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
                                                 20037508.34, 20037508.34)
};
map = new OpenLayers.Map('map', options);
var layer = new OpenLayers.Layer.Google("Google", {"sphericalMercator":
true});
map.addLayer(layer);
------------------------------

I do indeed get the google map layer displayed but what I ran into is that
these options change how the OL API handles or deals with latlon
coordinates.  For example, when I click on the map I get the following type
of "coordinate" when calling the OL getLatLongFromViewportPX() function:
(Lat: -39135.7584  / Lon: -273950.3093).  If I do a map.getExtent(), which
typically returns the latlon for the SW and NE boundary corners, now returns
a value like -381458.9896 / -722521.0097, -322984.6629 / -686366.2955. 
These are obviously not coordinates in degrees but some other value.  My
application is expecting a decimal coordinate in degrees, which OL returns
in the getgetLatLongFromViewportPX() and getExtent() function calls when
google maps are not used.  Now the app does not work.

I see that the "unit" value listed in the options is "m". Not sure if that
is meters or some other value.  The OpenLayers.Bounds value also does not
seem to be listed in a latlon coordinate.  In order to get my coordinate
values in degrees, is there another set of options to use or is there some
formula/algorithm that can be applied to what comes back from the OL
functions in order to get the value I am looking for.

Thanks for any insight - Peter



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



More information about the Users mailing list