Created
September 28, 2012 02:01
-
-
Save halfempty/3797570 to your computer and use it in GitHub Desktop.
Centering a Google Map on the Latest WordPress Post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri() ?>/map.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var infowindow = new google.maps.InfoWindow(); | |
var pinkmarker = new google.maps.MarkerImage('/wp-content/themes/mapdemo/pink_Marker.png', new google.maps.Size(20, 34) ); | |
var shadow = new google.maps.MarkerImage('/wp-content/themes/mapdemo/shadow.png', new google.maps.Size(37, 34) ); | |
function initialize() { | |
map = new google.maps.Map(document.getElementById('map'), { | |
zoom: 12, | |
center: new google.maps.LatLng(38.898748, -77.037684), | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}); | |
for (var i = 0; i < locations.length; i++) { | |
var marker = new google.maps.Marker({ | |
position: locations[i].latlng, | |
icon: pinkmarker, | |
shadow: shadow, | |
map: map | |
}); | |
google.maps.event.addListener(marker, 'click', (function(marker, i) { | |
return function() { | |
infowindow.setContent(locations[i].info); | |
infowindow.open(map, marker); | |
} | |
})(marker, i)); | |
} | |
} | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$the_query = new WP_Query('showposts=1'); | |
while ( $the_query->have_posts() ) : $the_query->the_post(); | |
$coordinates = get_geocode_latlng($post->ID); | |
endwhile; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
center: new google.maps.LatLng(38.898748, -77.037684), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
center: new google.maps.LatLng<?php echo $coordinates ?>, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment