Pregunta

Apologies in advance as this may seem a little complicated.

I have a Google Map Marker Array that my markers get added to called markersArray.

The details that get stored per marker are latitude, longitude, title, description.

Using the code below, it runs when a marker is clicked on my map

google.maps.event.addListener(marker, 'click', function(mll) {
                console.log(mll);
                console.log(markersArray);
                var html= "<div style='color:#000;background-color:#fff;padding:5px;width:150px;'><p></p></div>";
                iw = new google.maps.InfoWindow({content:html});
                iw.open(map,marker);
            });

mll shows the log for the actual marker and markersArray just shows me the list of markers within the Array.

What I've noticed is that the data stored in markersArray is no being taken into the actual marker itself.

Is there a way of doing this?

If there isn't is there a way to use Javascript to find the title from the markersArray depending on the latLng values that you will see in the following image.

I screenshot what I receive when I run the Marker Click Function

enter image description here

Markers are added as follows using AngularJS:

$scope.createmarker = function () {
    geocoder.geocode({
        'address': selectedItem.gps
    }, function (response, status) {
        geocode_results = new Array();
        geocode_results['status'] = status;

        top_location = response[0];
        var lat = Math.round(top_location.geometry.location.lat() * 1000000) / 1000000;
        var lng = Math.round(top_location.geometry.location.lng() * 1000000) / 1000000;
        geocode_results['lat'] = lat;
        geocode_results['lng'] = lng;
        geocode_results['l_type'] = top_location.geometry.location_type;
        marker = new google.maps.Marker({
            icon: mapIcon,
            position: new google.maps.LatLng(lat, lng),
            map: map,
            title: selectedItem.title
        });
        markersArray.push(marker);

        console.log(markersArray);
        console.log(marker);
    });
};
¿Fue útil?

Solución

Using title instead of mll

google.maps.event.addListener(marker, 'click', function(title) {
                console.log(mll);
                console.log(markersArray);
                var html= "<div style='color:#000;background-color:#fff;padding:5px;width:150px;'><p></p></div>";
                iw = new google.maps.InfoWindow({content:html});
                iw.open(map,marker);
            });
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top