0

I use a google map with javaScript and my code is :

 <script type="text/javascript">
    var map;
    function initialize() {
        var myLatlng = new google.maps.LatLng(-12.043333,-77.028333);
        var myOptions = {
        zoom: 17,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.SATELLITE
      };


      map = new google.maps.Map(document.getElementById('map_canvas'),
          myOptions);
      google.maps.event.addListener(map, "mousedown", function (e) {

                        //lat and lng is available in e object
                        var latLng = e.latLng;
                        console.log(latLng);
                    });
   }

    google.maps.event.addDomListener(window, 'load', initialize);
  </script>` 

The result of e.latLng is an empty object. I tried to click the event, but the result is empty. What should I do or change?

2
  • According to the documentation, there is no 'mousedown' event on the Map class. Maybe you want to use 'click' instead. Commented Sep 8, 2017 at 11:22
  • The object you are logging is a google.maps.LatLng object. It has a .lat(), .lng(), andto UrlValue() methods, try using them... fiddle Commented Sep 8, 2017 at 13:04

1 Answer 1

1

Your code is working fine :

Click on map and your coordinates will come in alert

Please check here

Sign up to request clarification or add additional context in comments.

1 Comment

it still not working :( the result :Object { lat: _.F/this.lat(), lng: _.F/this.lng() } i'm working with localhost

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.