-1

I'm trying to get the lat, lng separately from google maps, I have already the position, what should I do?!!

function initialisation(){ 
    var centreCarte = new google.maps.LatLng(36.846815, 10.198352); 
    var optionsCarte = { 
        zoom: 17, 
        center: centreCarte, 
        mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 
    var maCarte = new google.maps.Map(document.getElementById("EmplacementDeMaCarte"), optionsCarte);

    google.maps.event.addListener(maCarte, 'click', function(event) {
        var Mark =(new google.maps.Marker({
            position: event.latLng,//coordonnée de la position du clic sur la carte
            draggable: true, //marqeur daplacable
            title:'marker',//titre des marqeur
            map: maCarte//la carte sur laquelle le marqueur doit être affiché
        }));

        google.maps.event.addListener(Mark, 'dblclick', function(event) {
            function sayHello() {
                var te = Mark.getPosition().toUrlValue();
                return te ;
            }
            alert(sayHello());
        });

        //rightclick
        google.maps.event.addListener(Mark, 'rightclick', function(event){
            Mark.setMap(null);
        });
    });
}

google.maps.event.addDomListener(window, 'load',initialisation);
davidkonrad
  • 83,997
  • 17
  • 205
  • 265
user3664298
  • 21
  • 1
  • 2
  • 6
  • 2
    Argument to map `click` event handler is object of `MouseEvent` type. It has property `latLng` which you use to get position. That property is of type `LatLng` which has methods `lat()` and `lng()`. So, you can use `event.latLng.lat()` and `event.latLng.lng()`. – Anto Jurković May 22 '14 at 10:55
  • possible duplicate of [Latitude, Longitude Grabber](http://stackoverflow.com/questions/5571641/latitude-longitude-grabber) – Anto Jurković May 22 '14 at 11:00

1 Answers1

1

Just use .lat() and .lng() on your LatLng object.

In your case, you can get latitude and longitude of your clicked marker using

var latitude = event.latLng.lat();
var longitude = event.latLng.lng();
AlexB
  • 7,302
  • 12
  • 56
  • 74