AnsweredAssumed Answered

How to get the coordinates of the pin/marker?

Question asked by siyakubeka on Jan 7, 2020

Hi,

 

I have this JavaScript code that allows me to drop a pin/marker on to a map. Now I want to get the coordinates of the dropped pin. How do I do that? Please see code below:

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>APPLICATION</title>

<link
rel="stylesheet"
href="https://js.arcgis.com/4.12/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.12/"></script>

<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<script>
require([
"esri/widgets/Sketch",
"esri/Map",
"esri/layers/GraphicsLayer",
"esri/views/MapView"
], function(Sketch, Map, GraphicsLayer, MapView) {
const layer = new GraphicsLayer();

const map = new Map({
basemap: "streets",
layers: [layer]
});

const view = new MapView({
container: "viewDiv",
map: map,
zoom: 5,
center: [90, 45]
});

const sketch = new Sketch({
layer: layer,
view: view,
availableCreateTools: ["point"]
});

view.ui.add(sketch, "top-right");

sketch.on('create', function(evt){
console.info(evt.graphic.geometry);
});
});
</script>
</head>

<body>
<div id="viewDiv"></div>
</body>
</html>

Outcomes