Reputation: 3118
My code below trigger a simple Google Map event when the user click on the marker:
google.maps.event.addListenerOnce(marker, 'click', function() {
console.log(this.position);
}
It displays the current position of the clicked marker like this:
of {j: 51.469722, C: -0.4513890000000629}
In my application, I was fetching the Latitude and the Longitude of the clicked marker by using the index of the returned position:
var positions = this.position;
var latitude = positions[0].j;
var longitude = positions[0].C;
It was working fine until i found out that the index of this.position are dynamic, it can change at any time. instead of j and C I can have k and D as an index for each element of the position object.
Can someone help me to figure it out how I can manipulate the position of a marker without hard-coding the index and not breaking my code if the letters change?
Upvotes: 0
Views: 172
Reputation: 2853
var lat = this.getPosition().lat();
var lng = this.getPosition().lng();
Generally there are getters and setters for many things in GM, and you should look for those in the docs before going into the inspector.
Upvotes: 1