This was a real gnarly one. So I’m not going to describe the problem – I figure if you got here via Google, then you have a similar setup sequence as in the title of this post, and subsequently you’ll be hurting real bad and willing to look at any freakn’ code. CCK Multigroup for Drupal 6 is one of the jankiest modules out there, yet it’s applications are so useful. Team that up with the equally janky Location module, and… kill me.
Anyway, enough said, here’s some script:
<?php $result = db_query('SELECT city, latitude, longitude FROM {location} WHERE lid = %d', $_GET['location']);
$festcity = db_fetch_object($result);
$city = $festcity->city;
$latm1 = $festcity->latitude;
$lonm1 = $festcity->longitude; ?>
<script type="text/javascript">
$(function() {
var latlng = new google.maps.LatLng(<?php echo $latm1; ?> , <?php echo $lonm1; ?> );
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "<?php echo $city; ?>"
});
})
</script>
And look here’s some more, thanks Googlemaps:
<script type="text/javascript">
var map;
var global_markers = [];
<?php
$markers = array();
foreach ($node->field_location as $location) {
$lat = $location['latitude'];
$lon = $location['longitude'];
$city = $location['city'];
$markers[] = "[$lat , $lon , '$city']";
}
$strMarkers = "[";
foreach($markers as $marker) {
$strMarkers .= $marker. ',';
}
$strMarkers .= "]";
print "var markers = $strMarkers;";
?>
function initialize() {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 3,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
addMarker();
}
function addMarker() {
for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i][0]);
var lng = parseFloat(markers[i][1]);
var trailhead_name = markers[i][2];
var myLatlng = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: trailhead_name
});
}
}
var infowindow = new google.maps.InfoWindow({});
</script>
And now, ladies and gentlemen, you can display a Google Map marking your co-ordinates of multiple locations, inside a div where display:none, and when display:block, it will work like a dream, thus:
<div style="display:none">
<div id='map_canvas' style='width:622px; height:280px; margin:15px 0 30px 0;'></div>
</div>
If anyone wants to reverse-engineer this, explain it, and even better it (I know it’s very possible to do so) be my guest.