jeudi 1 février 2018

Display marker to google maps

I've been wanting to display a marker to google maps. I can already get the latitude and longitude from the database but my problem is it wont display the marker. This is my code.

    var locations = [
    <?php foreach($routes as $route){?>
        {
            "title": "",
            "lat": "",
            "lng": ""
        },

    <?php } ?>
];
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i].lat,locations[i].lng),
        icon: pin,
        map: map
    })

    google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
            infowindow.setContent(locations[i].title);
            infowindow.open(map, marker);
        }
    })(marker, i));

    console.log(locations[i].lat);
    console.log(locations[i].lng);
}

I tried to do a console.log to the latitude and longitude and it successfully displayed but the marker wont show up.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2E7A2Ha
via IFTTT

Aucun commentaire:

Enregistrer un commentaire