# Get coordinates from a drawing point using OpenLayers 2

I implemented a drawing feature (OpenLayers2) on an OpenStreetMap.

I searched about how to get coordinates from a drawing point. But I'm still stuck at this point.

I tried this code in order to get the coordinates instantly after drawing a new point but with no success:

`````` // HOW TO ADD A DRAWING FEATURE
var DrawMyPoint = new OpenLayers.Control.DrawFeature( MyPointLayer, OpenLayers.Handler.Point)//,
//{feature:GetPointCoordinates});
// Point for creating point, polygon creating polygon, and so on.

document.getElementById("DrawCheckBox").checked = PushOnButtonDraw();
document.getElementById("DrawCheckBox").checked =GetPointCoordinates();

// FUNCTION TO GET COORDINATES OF THE POINT
function GetPointCoordinates(){
var coordinates = MyPointLayer.geometry.getBounds();
console.log(coordinates);
}
``````

Here is a link where I saw the information about getBounds or getCoordinates : Openlayers get coordinates from polygon

I am not sure if I may link two functions with the same event, or is there another solution about it?

With getting the coordinates of each newest drawing point (which is my initial question), I would center the map to this coordinates too.

Do you have any idea?

– PolyGeo
Commented Jun 22, 2017 at 20:06
• I found the answer to my problem. Here is the code i used : / / HOW TO LINK THIS POINT LAYER INTO AN EVENT MyPointLayer.events.on({ featuresadded : GetCoordinatePoint }); function GetCoordinatePoint(event) { var Mycoordonate = event.features[0].geometry.getVertices(); var stringVertices = ""; for (var x in Mycoordonate) { stringVertices += "(" + Mycoordonate[x].x + "," + Mycoordonate[x].y + ")"; } console.log(stringVertices); } Commented Jun 23, 2017 at 9:22
• @Karro post it as an answer so people can finds it more easily :) Commented Jun 23, 2017 at 9:42

``````MyPointLayer.events.on({ featuresadded : GetCoordinatePoint });
`for (var x in Mycoordonate) { stringVertices += "(" + Mycoordonate[x].x + "," + Mycoordonate[x].y + ")"; }`
`console.log(stringVertices); }`