2

I have been trying to use google street maps with the help of OpenLayers, but Every time I am running into a problem with this google maps coordinates.

The Coordinates of a location named 'Asab, in Abu Dhabi' should have coordinates as "Longitude=54.3004105, Latitude=23.25535006" but instead it gives coordinates like "Long=6036690.74501, Lat=2700367.334".

The Code I used to include google maps into my HTML webpage is as below: var map;

function init(){
// Initiating 'map' Variable and Adding Controls
map = new OpenLayers.Map('map_element', {
 controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.ZoomBox(),
new OpenLayers.Control.ZoomToMaxExtent(),
new OpenLayers.Control.LayerSwitcher({}),
new OpenLayers.Control.MousePosition('mouse_position', { prefix: 'Long: ', separator: ' \n| Lat: '}),
new OpenLayers.Control.ScaleLine({}),
new OpenLayers.Control.OverviewMap()
]
});

// BaseMap Layers
var google_streets= new OpenLayers.Layer.Google(
'Google Streets', 
{type: google.maps.MapTypeId.ROADMAP,
        units: "m",
        maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
                                             20037508.34, 20037508.34),
        maxResolution: 1.40625
}, {"sphericalMercator": true}
);

So I have been looking all over to correct this but I am not getting how to do it. I am a new learner into this OpenLayers, so if someone can please give me push it would be really helpful.

  • Can it be another projection system that generates those coordinates? You've used WGS 84? – CARTOS Mar 28 '14 at 6:52
  • yes surely any projection system would work as far as it gives us the correct coordinates for locations, when cross-checked on the actual GOOGLE MAPS website – abhinavgoyal02 Mar 28 '14 at 6:56
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. – Simbamangu Mar 28 '14 at 11:12
4

You can set on the start of openlayers script with:

    function init(){
        var option = {
            projection: new OpenLayers.Projection("EPSG:3857"),
            displayProjection: new OpenLayers.Projection("EPSG:4326")

        };

or in the layer with trasformation

            extent = new OpenLayers.Bounds($SO_ln.",".$SO_lt.",".$NE_ln.",".$NE_lt).transform(new OpenLayers.Projection('EPSG:4326'), 
        new OpenLayers.Projection('EPSG:3857'));
  • you answer was spot.... thanks a lot I could only get your 1st method to work and not the 2nd one. Great answer really! :-) – abhinavgoyal02 Mar 28 '14 at 9:37
3

The first coordinates are in WGS84 longlat degrees EPSG:4326, while the second ones are in Spherical Mercator "metres" , EPSG:3857.

This is what you set the display projection to, so no reason to get worried about.

In QGIS, with a Openstreetmap background, your points look like this:

enter image description here

  • Andre the map you used seems like Open Source Map, whereas mine is Google Maps and unless my coordinates do not come right it is quite a trouble. I am using the mouse position control to see the coordinates and they do not seem to be correct. What shall I do? – abhinavgoyal02 Mar 28 '14 at 7:09
  • 2
    Google Map uses the same projection as Openstreetmap. You have to take care about the difference between projection and display projection, as given in another answer. – AndreJ Mar 28 '14 at 7:30
  • Thank u @Andre it actually worked what you suggested to do the way pjhooker said in the answer. Somehow the pjhooker's 1st idea works and not the second. But still I am grateful to you people. – abhinavgoyal02 Mar 28 '14 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.