Add locations to map

This commit is contained in:
Markus Ankenbrand 2017-02-19 18:06:47 +01:00
parent 544d31a478
commit 2619b450b5

View file

@ -41,6 +41,10 @@
<?php edit_post_link(__('Edit Page','hitchcock'), '<div class="post-meta"><p class="post-edit">', '</p></div>'); ?>
</div> <!-- /post-inner -->
<div class="post-meta">
<div class='map' style='height:300px; margin-bottom: 1.6842em' id='map-stats'></div>
</div> <!-- /post-meta -->
<?php comments_template( '', true ); ?>
@ -65,12 +69,39 @@
$places = get_field('orte');
if($places){
foreach ($places as $place){
$locations[] = array("post" => $post->ID, "place" => $place);
$locations[] = array_merge(array("post" => $post->ID), $place);
}
}
endwhile;
var_dump($locations);
?>
<script type='text/javascript'>
var places = <?php echo json_encode($locations); ?>;
var map;
var map_center = {lat: parseFloat(places[0]['lat']), lng: parseFloat(places[0]['lng']) };
function initMap() {
map = new google.maps.Map(document.getElementById('map-stats'), {
center: map_center,
zoom: 15
});
var bounds = new google.maps.LatLngBounds();
for(var i = 0; i < places.length; i++){
var marker = new google.maps.Marker({
position: {lat: parseFloat(places[i]['lat']), lng: parseFloat(places[i]['lng']) },
map: map
});
marker.setVisible(true);
bounds.extend(marker.getPosition());
}
map.fitBounds(bounds);
window.setTimeout(function(){
if(map.getZoom() > 15){
map.setZoom(15);
}
}, 500)
}
</script>
<?php get_footer(); ?>