1

When trying to define coordinates on my map, I get a different result depending if I hardcode the lon/lat or if they are coming from the database.

document.title = eventName;
document.getElementById("titleEventName").innerHTML = ol.proj.fromLonLat([5.942060,50.751453]);
document.getElementById("tempEventName").innerHTML = ol.proj.fromLonLat([eventCenterMapLongitude, eventCenterMapLatitude]);
document.getElementById("tempEventName2").innerHTML = "eventCenterMapLongitude = " + eventCenterMapLongitude + ", eventCenterMapLatitude = " + eventCenterMapLatitude;
document.getElementById("tempEventName3").innerHTML = ol.proj.transform([661467.0934630792,-4757336.459308266], 'EPSG:3857', 'EPSG:4326');

In the first line, I just display the coordinates by setting them manually. In the second line, I retrieve them from variables set out of the database. In the third line, I show the values of those variables (which are the same as the hardcoded ones). In the 4th line, I re-convert back to lat/lon, and I see that the longitude is ok, but the latitude is 90° lower than the initial latitude.

Here is the output on my screen:

661467.0934630792,6577445.839458974
661467.0934630792,-4757336.459308266
eventCenterMapLongitude = 5.942060, eventCenterMapLatitude = 50.751453
5.942060000000001,-39.24854609999999

What is wrong here? Why do I get -4757336.459308266 in the second line instead of 6577445.839458974?

Tim D
  • 11
  • 2

1 Answers1

0

It looks like you are using different coordinate systems. See Openlayers 3 center map and http://openlayers.org/en/v3.1.1/apidoc/ol.proj.html

Community
  • 1
  • 1
Michael Oakley
  • 383
  • 3
  • 5
  • Nope, because then it wouldn't work when I manually enter the coordinates. But I found the issue myself (after 2 days of looking :( ). https://github.com/openlayers/ol3/issues/4989 --> my database values are strings and not numbers. This works (just by luck) for longitudes, but not for latitudes. So a simple: Number (mydatabaselonglat) does the trick – Tim D Apr 19 '16 at 13:26