Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I need to show a map (world map, used default OpenLayers WMS) and one point on it (with events like onhover, etc). Here is my code:

                   var options = {
                            projection: new OpenLayers.Projection("EPSG:900913"),
                            maxResolution: 6000
                        };
                        map = new OpenLayers.Map('map', options);

                        var wmsLayer = new OpenLayers.Layer.WMS(
                        "OpenLayers WMS", 
                        "http://vmap0.tiles.osgeo.org/wms/vmap0",
                        {layers: 'basic'}
                    ); 

                    var vectors = new OpenLayers.Layer.Vector("Vector Layer");

                    point = new OpenLayers.Geometry.Point(20.088844299316406, 51.8321709083475);
                    vectors.addFeatures([new OpenLayers.Feature.Vector(point)]);

                    map.addLayers([wmsLayer, vectors]);

                    map.zoomToMaxExtent();

But this code locates the point is drawn not in correct place, but somewhere near Africa (that place lat and lon is 0, 0). Question: Why this happens and can I fix it? I just need to locate the point to the correct place. Paradox when I print this point in console then it shows that the point lan and lon are as needed (as defined). But it is still in the wrong place...

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

You need to translate the point from lat/lon to your map projection:

point = new OpenLayers.Geometry.Point(20.088844299316406, 51.8321709083475);    
point.transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
vectors.addFeatures([new OpenLayers.Feature.Vector(point)]);

This will transform your variable point to the map projection.

share|improve this answer
    
This does not helped... point is still near Africa –  Bob Oct 28 '12 at 19:27
    
fixed typo..... –  djq Oct 28 '12 at 19:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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