This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

[closed] map.getBounds() Not Working…

0

How to get map corner latlong in OSM. i have many tried to solve it but i did not solve it.

i have use below example.

===================================================

<html> <head> <title>OpenLayers Demo</title> <style type="text/css"> html, body, #basicMap { width: 100%; height: 100%; margin: 0; } </style>

<script src="http://www.openlayers.org/api/OpenLayers.js" type="text/javascript"></script>

<script type="text/javascript">
    function init() {
        var marker_layer = new OpenLayers.Layer.Markers("Markers");

        var map = new OpenLayers.Map("basicMap");
        var mapnik = new OpenLayers.Layer.OSM();
        var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984
        var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection

        var position1 = new OpenLayers.LonLat(78.9629, 20.5937).transform(fromProjection, toProjection);
        var position2 = new OpenLayers.LonLat(79.2629, 20.9937).transform(fromProjection, toProjection);
        var zoom = 8;

        map.addLayer(mapnik);
        map.setCenter(position1, zoom);


        debugger;

        var bounds = map.getBounds();       //Error : map.getBounds is not a function

        var vv1 = map.getView().calculateExtent();  //Error : map.getView is not a function

    }
</script>

</head> <body onload="init();">

</body> </html>

===================================================

asked 15 Jul '16, 08:30

Jatin%20Patel's gravatar image

Jatin Patel
11557
accept rate: 0%

closed 16 Jul '16, 07:47

scai's gravatar image

scai ♦
33.3k21309459

If possible then write a solution for above query...

Thanks in advance.

(16 Jul '16, 07:13) Jatin Patel

The question has been closed for the following reason “Duplicate Question, see https://help.openstreetmap.org/questions/50696/how-to-get-map-corner-latlong-using-open-layer" by scai 16 Jul ‘16, 07:47

Source code available on GitHub .