2

I would get the coordinate from an openlayers map. When I open my page I would that when I click on a button, I have received the coordinate of top bottom left and the upper right.

 <html>
<head>
  <title>OpenLayers Example</title>
    <script src="http://openlayers.org/api/OpenLayers.js"></script>
    </head>
    <body>
      <div style="width:100%; height:100%" id="map"></div>
      <script defer="defer" type="text/javascript">
        var map = new OpenLayers.Map('map');
        var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
            "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
        map.addLayer(wms);
        map.zoomToMaxExtent();
      </script>
<input type="button" text="Get Coordinate from map">
</body>
</html>

Thanks a lot.

2 Answers 2

4

You should use the getExtent() function of the Map object.

Returns

{OpenLayers.Bounds} A Bounds object which represents the lon/lat bounds of the current viewPort.

It will return you an OpenLayers.Bounds object, which will have the top, left, bottom and right coordinates of the current view.

Sign up to request clarification or add additional context in comments.

1 Comment

You can use .toBBOX() to get a string version of the bounds, and you can generate your button to this using any standard Javascript approaches.
0

I think you want to use map.getCenter() ? (this is in case you want the center coordinates of the map in lat lon, but it's not really clear what coordinate you want)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.