0
votes

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);
    });
};
1
Where is the part where you add these properties? And where is the part where you add each marker to the array? - MrUpsidown
How do you store markers and their details into markersArray? - Anto Jurković
I have added how markers are added to the array - ngplayground
I see no description added to the marker but anyway... Did you try to log selectedItem.title? Do you really have something in there? - MrUpsidown
@AntoJurković thank you! I think you have just sussed it out! I was using mll instead of looking through the marker I will buy you a pint! - ngplayground

1 Answers

0
votes

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);
            });