Skip to content

Instantly share code, notes, and snippets.

@atleastimtrying
Forked from MatthewRewired/map.php
Last active January 1, 2016 15:29
Show Gist options
  • Save atleastimtrying/8164301 to your computer and use it in GitHub Desktop.
Save atleastimtrying/8164301 to your computer and use it in GitHub Desktop.
<?php
require 'includes/mapData.php';
?>
var map;
var living1 = new google.maps.LatLng(37.3333, -121.9000);
var MY_MAPTYPE_ID = 'custom_style';
var initialize = function() {
var featureOpts = [
{
stylers: [
{ hue: '#000044' },
{ visibility: 'simplified' },
{ gamma: 0.5 },
{ weight: 0.5 }
]
},
{
elementType: 'labels',
stylers: [
{ visibility: 'on' }
]
},
{
featureType: 'water',
stylers: [
{ color: '#000044' }
]
}
];
var mapOptions = {
zoom: 12,
center: living1,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
},
mapTypeId: MY_MAPTYPE_ID
};
var map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
var styledMapOptions = {
name: 'Custom Style'
};
var customMapType = new google.maps.StyledMapType(featureOpts, styledMapOptions);
map.mapTypes.set(MY_MAPTYPE_ID, customMapType);
// each of these vars are defined here as your php loop will keep redefining these four variables, in an ideal world this loop would be in js not php
var setupLocation = function(lat, lng, contentHTML){
var latLng = new google.maps.LatLng(lat, lng);
var infoWindow = new google.maps.InfoWindow({ content: contentHTML });
var marker = new google.maps.Marker({
position: latLng,
draggable:false,
title:"Centre"
});
//sets marker on map
marker.setMap(map);
google.maps.event.addListener(marker, 'click', function() {
infoWindow.open(map,marker);
});
};
<?php foreach($locations as $location) { ?>
setupLocation('<?php echo $location[1]; ?>', '<?php echo $location[2]; ?>', '<div>'+
'<h4 id="firstHeading" class="firstHeading"><?php echo $location[0]; ?></h4>'+
'<div id="bodyContent">'+
'<p><b><?php echo $location[0]; ?></b>' +
'<?php echo $location[3]; ?>'+
'<?php echo $location[4]; ?>'+
'<?php echo $location[5]; ?>'+
'<?php echo $location[6]; ?> '+
'<?php echo $location[7]; ?> '+
'<?php echo $location[8]; ?> '+
'<?php echo $location[9]; ?> '+
'</div>'+
'</div>');
<?php } ?>
};
google.maps.event.addDomListener(window, 'load', initialize);
<?php
$locations = array
(
array(
"Gilroy National Guard Armory",//00
37.02043,//01
-121.5617,//02
", 8490 Wren Avenue, Gilroy, 95020,",//03
"Near Las Animas Park.",//04
"Telephone: 712-0453.", //05
"Clients must be onsite by 6:00 pm for intake.", //06
"Space limited to 100.", //07
"Offsite nights each month due to Guard exercises.", //08
"Meals served daily." //09
),
array(
"Boccardo Reception Center",//00
37.30345,//01
-121.87065,//02
", 2011 Little Orchard, San Jose, 95125,",//03
"Near The Plant shopping area.",//04
"Telephone: 408-510-7502.", //05
"Clients must be onsite by 3:30 pm to join the lottery for bed assignments. ", //06
"Space limited to 50. ", //07
"Shelter opens at 4:00pm. ", //08
"Meals served daily. " //09
),
array("BMW",60,59),
array("Toyota",110,100)
);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment