question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get lat and long on click?

See original GitHub issue

I just tried $(".mapcontainer").data('mapael').mapPagePositionToXY(e.pageX, e.pageY). I am getting the x and y co-ordinates which I am saving into database. And showing it somewhere. Now, I want to save the lat and long into database and show the same. How can I get the lat and long from the clicked position?

Currently, I am using this to get the current x and y position.

$(".mapcontainer").on('click', function (e) {
            
            var coords = $(".mapcontainer").data('mapael').mapPagePositionToXY(e.pageX, e.pageY), plotId = 'plot-' + Math.round(Math.random() * 1000), updateOptions = { 'newPlots': {}, 'replaceOptions': { resetPlots: true }, deletePlotKeys: plots };

            plots.push(plotId);
            updateOptions.newPlots[plotId] = {
                x: coords.x,
                y: coords.y,
                value: "unknown"
            };

            selectedlat = coords.x;
            selectedlong = coords.y;

            ReInitialize(updateOptions);

        });

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ankitdholakiyacommented, Jan 5, 2018

I think adding that function should give the more flexibility to this tool. This way the users will directly get an idea what they need to do to achieve something. I spent a whole day finding this out 😃

0reactions
neveldocommented, Jan 5, 2018

You’re right, at least a little bit of documentation would be welcome on this topic 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Lat/Lng from a Click Event | Maps JavaScript API
To navigate, press the arrow keys. Click the map to get Lat/Lng! zoom: 4, center: myLatlng,
Read more >
how to get latitude, longitude onclick of a map in google maps ...
You have to use event argument. google.maps.event.addListener(map, 'click', function(event) { marker = new google.maps.
Read more >
Getting Lat, Long of clicked location using Leaflet API?
You can easily get click events using the map's 'on' event subscription method: map.on('click', function(e) { alert("Lat, ...
Read more >
Calculating a Location from a Mouse Click - Maps API for ...
Obtain the latitude and longitude of a location within the map. ... The tap event holds the x and y screen coordinates of...
Read more >
Google Maps: Get Latitude/Longitude value on Click and on ...
This article shows how to get latitude and longitude value when you click or move the mouse over Google Map.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found