Im trying to use google maps to display artist tour dates with points on the map. I have Lat/Lon getting queried in php, There is about 20 results that all have lat/lon. When I plug the values into the google map javascript only one result is showing on the map. What am I doing wrong here?
php
$lat = get_field('gp_latitude');
echo json_encode($lat)."<br>";
$lon = get_field('gp_longitude');
echo json_encode($lon)."<br>";
$infobox = get_the_title();
echo json_encode($infobox). "<br>";
$postid = get_the_ID();
echo json_encode($postid). "<br><br>";
javascript
<script type="text/javascript">
var locations = [
['<?php echo json_encode($infobox) ?>', <?php echo json_encode($lat) ?>, <?php echo json_encode($lon) ?>, <?php echo json_encode($postid) ?>, 2],
['<?php echo json_encode($infobox) ?>', <?php echo json_encode($lat) ?>, <?php echo json_encode($lon) ?>, <?php echo json_encode($postid) ?>, 1]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: new google.maps.LatLng(-33.92, 151.25),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
Aucun commentaire:
Enregistrer un commentaire