AnsweredAssumed Answered

JS API wrong latitude

Question asked by MaikLehmann on Jul 14, 2017
Latest reply on Jul 15, 2017 by MaikLehmann

Hello,

 

I'm using the following code to display a map and to get the longitude and latitude of a point which is clicked on the map. Whenever I use this code on a stand alone, black page, everything works as expected. As soon as I surround the output <div id="map-container"></div> with my additional code, the value for longitude is always wrong. After hours of trying, to re do the code and to solve the issue somehow, I'm running out of my mind. Any idea what is going wrong?

Output of the short php code is 54.563,24.423

 

thank you.

 

<script>
function initMap(){
var map;
require([
"esri/Map",
"esri/views/MapView",
"esri/geometry/Point",
"esri/symbols/SimpleMarkerSymbol",
"esri/Graphic",
"esri/layers/GraphicsLayer",
"esri/symbols/PictureMarkerSymbol",
"dojo/domReady!",
"dojo/query",
"dojo/dom-class",
"esri/PopupTemplate"
], function(
Map, MapView, Point, SimpleMarkerSymbol, Graphic, GraphicsLayer, PictureMarkerSymbol, query, domClass, PopupTemplate
) {
var map = new Map({
basemap: "streets"
});
var view = new MapView({
container: "map-container",
map: map,
zoom: 12, 
center: [<?php projectlocation($projectid); ?>] 
});
view.on("click", function(event) {
// Get the coordinates of the click on the view
var lat = event.mapPoint.latitude;
var lon = event.mapPoint.longitude;
document.getElementById("latFld").value = lat;
document.getElementById("lngFld").value = lon;
// Create a symbol for drawing the point
var markerSymbol = new PictureMarkerSymbol({
url: 'images/marker_red.png'
});
var pointGraphic = new Graphic({
geometry: event.mapPoint,
symbol: markerSymbol
});
// Add the graphics to the view's graphics layer
view.graphics.removeAll();
view.graphics.add(pointGraphic);
});
});
}

Outcomes