Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert point to lat lon

Tags:

I wonder, how can I get map click event's coordinates as lat,lon?

Here is my code:

map.on('click', function(evt) {     var element = popup.getElement();     var coordinate = evt.coordinate;      var latLon = ol.proj.transform(coordinate, 'EPSG:3857', 'EPSG:4326');      $(element).popover('destroy');     popup.setPosition(coordinate); 

Normally, coordinate value gives me an array etc: [48654.02545, 3265468.45455]

But I need lat lon etc:([39,54876,32,547821])

Abstract: I need to convert epsg:3857 coordinate to epsg:4326 coordinate (lat/lon)

Any idea?

like image 786
gokhangokce Avatar asked Nov 17 '14 07:11

gokhangokce


1 Answers

If your map view projection is Web Mercator (EPSG:3857), which is the default, then the following should work:

map.on('click', function(evt) {   var lonlat = ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326');   var lon = lonlat[0];   var lat = lonlat[1];   // … }); 
like image 80
erilem Avatar answered Oct 15 '22 16:10

erilem