<?php

$locations = array();
while (have_posts()) {
    the_post();
    $distance = facetwp_get_distance($post->ID);
    $distance = false !== $distance ? '<br />' . round($distance, 1) . ' miles away' : '';
    $locations[] = array('title' => get_the_title($post->ID), 'coords' => get_post_meta($post->ID, 'coordinates', true), 'distance' => $distance);
}
?>
<script>window.map_data = <?php 
echo json_encode($locations);
?>
;</script>
			 <!-- Map -->
			<div class="map--display">
	        	<div id="map" style="height:550px"></div>
	        </div>


    		<?php 
// echo facetwp_display( 'template', 'hikes' ); // hidden from view
?>
    		<div class="facetwp-template">
				<?php 
$q = new wp_query(array('post_type' => 'hikes', 'posts_per_page' => 100));
while ($q->have_posts()) {
    $q->the_post();
    $title = get_the_title(get_the_ID());
    $distance = facetwp_get_distance(get_the_ID());
    $distance = false !== $distance ? round($distance, 1) . ' miles away' : '';
    $location = fo_get_hike_gps_location();
    $lat = isset($location['0']) ? $location['0'] : false;
    $long = isset($location['1']) ? $location['1'] : false;
    ?>
<div class="map-item"
								style="display:none"
								data-title="<?php 
    echo esc_attr($title);
    ?>
"
								data-latitude="<?php 
    echo $lat;
    ?>
"