Skip to content

Instantly share code, notes, and snippets.

@designbuildtest
Last active August 29, 2015 14:02
Show Gist options
  • Save designbuildtest/132b5167297c628f9eb8 to your computer and use it in GitHub Desktop.
Save designbuildtest/132b5167297c628f9eb8 to your computer and use it in GitHub Desktop.
Google Map integration
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["map"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Lat', 'Long', 'Name'],
<?php
$args = array(
'post_type' => 'post',
'ignore_sticky_posts' => true,
'posts_per_page' => 400,
'meta_query' => array(
array(
'key' => 'geo_public',
'value' => 'true',
)
),
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) : $loop->the_post();
$lat = esc_attr( get_post_meta( get_the_ID(), 'geo_latitude', true ) );
$lng = esc_attr( get_post_meta( get_the_ID(), 'geo_longitude', true ) );
$content = sprintf( '<a href="%1$s">%2$s</a>',
esc_url( get_permalink() ),
esc_attr( get_the_title() )
);
?>
[ <?php echo $lat; ?>, <?php echo $lng; ?>, '<?php echo $content; ?>' ],
<?php
endwhile;
endif;
wp_reset_query();
?>
]);
var map = new google.visualization.Map(document.getElementById('map'));
map.draw(
data, {
showTip: true,
mapType: 'normal',
useMapTypeControl: true
}
);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment