Created
December 28, 2013 20:41
-
-
Save MatthewRewired/8163981 to your computer and use it in GitHub Desktop.
Ok I have a load of variables stored in external mapData.php file (which will eventually be a database) which seem to be loading in and populating the contentstring, lat/lng for map marker just fine, but I want the project to be scalable. So I need variables to be dynamic based on the amount of sets in the database. Every time round the loop it …
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 | |
require 'includes/mapData.php'; | |
?> | |
var map; | |
var living1 = new google.maps.LatLng(37.3333, -121.9000); | |
var MY_MAPTYPE_ID = 'custom_style'; | |
function initialize() { | |
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 | |
}; | |
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); | |
<!-- foreachl --> | |
<?php for ($x=0; $x<1; $x++) { ?> | |
<!-- needs unique location name, contentstring name, marker name and infowindow name everytime round the loop--> | |
var locStr= '<?php echo $locations[$x][12]; ?>'; <!--generates location varaible name from php, but doesn't --> | |
var conStr= '<?php echo $locations[$x][11]; ?>'; <!--generates contentstring varaible name from php, but doesn't --> | |
var infoWin= '<?php echo $locations[$x][10]; ?>'; <!--generates infowindow variable name from php, but doesn't --> | |
var marStr= '<?php echo $locations[$x][13]; ?>'; <!--generates marker variable name from php, but doesn't --> | |
var locStr = new google.maps.LatLng('<?php echo $locations[$x][1]; ?>', '<?php echo $locations[$x][2]; ?>'); | |
var conStr = '<div>'+ | |
'<h4 id="firstHeading" class="firstHeading"><?php echo $locations[$x][0]; ?></h4>'+ | |
'<div id="bodyContent">'+ | |
'<p><b><?php echo $locations[$x][0]; ?></b>' + | |
'<?php echo $locations[$x][3]; ?>'+ | |
'<?php echo $locations[$x][4]; ?>'+ | |
'<?php echo $locations[$x][5]; ?>'+ | |
'<?php echo $locations[$x][6]; ?> '+ | |
'<?php echo $locations[$x][7]; ?> '+ | |
'<?php echo $locations[$x][8]; ?> '+ | |
'<?php echo $locations[$x][9]; ?> '+ | |
'</div>'+ | |
'</div>'; | |
var infoWin = new google.maps.InfoWindow({ content: conStr }); | |
var marStr = new google.maps.Marker({ | |
position: locStr, | |
draggable:false, | |
title:"Centre" | |
}); | |
//sets marker on map | |
marStr.setMap(map); | |
google.maps.event.addListener(marStr, 'click', function() { | |
infoWin.open(map,marStr); | |
}); | |
//end of loop | |
<?php } ?> | |
//marker2 | |
//marker2 | |
var boccardo = new google.maps.LatLng('<?php echo $locations[1][1]; ?>', '<?php echo $locations[1][2]; ?>'); | |
var contentString2 = '<div>'+ | |
'<h4 id="firstHeading" class="firstHeading"><?php echo $locations[1][0]; ?></h4>'+ | |
'<div id="bodyContent">'+ | |
'<p><b><?php echo $locations[1][0]; ?></b>' + | |
' <?php echo $locations[1][3]; ?>'+ | |
' <?php echo $locations[1][4]; ?>'+ | |
' <?php echo $locations[1][5]; ?>'+ | |
' <?php echo $locations[1][6]; ?>'+ | |
' <?php echo $locations[1][7]; ?>'+ | |
' <?php echo $locations[1][8]; ?>'+ | |
' <?php echo $locations[1][9]; ?>'+ | |
'</div>'+ | |
'</div>'; | |
var infowindow2 = new google.maps.InfoWindow({ | |
content: contentString2 | |
}); | |
var marker2 = new google.maps.Marker({ | |
position: boccardo, | |
draggable:false, | |
title:"Centre" | |
}); | |
//sets marker on map | |
marker2.setMap(map); | |
google.maps.event.addListener(marker2, 'click', function() { | |
infowindow2.open(map,marker2); | |
}); | |
//end of marker 2 | |
//marker3 | |
var sunnyvale = new google.maps.LatLng(37.38520, -122.01697); | |
var contentString3 = '<div>'+ | |
'<h4 id="firstHeading" class="firstHeading">Sunnyvale National Guard Armory</h4>'+ | |
'<div id="bodyContent">'+ | |
'<p><b>Sunnyvale National Guard Armory</b>' + | |
', 620 E. Maude Sunnyvale, 94086, '+ | |
' Near the Fair Oaks / Wolfe Road split, '+ | |
'408-739-6980, '+ | |
' '+ | |
'Clients must be onsite by 6:00pm for intake. '+ | |
'Space limited to 125. '+ | |
'Offsite nights each month due to Guard exercises. '+ | |
'Meals served daily. '+ | |
'</div>'+ | |
'</div>'; | |
var infowindow3 = new google.maps.InfoWindow({ | |
content: contentString3 | |
}); | |
var marker3 = new google.maps.Marker({ | |
position: sunnyvale, | |
draggable:false, | |
title:"Centre" | |
}); | |
//sets marker on map | |
marker3.setMap(map); | |
google.maps.event.addListener(marker3, 'click', function() { | |
infowindow3.open(map,marker3); | |
}); | |
//end of marker 3 | |
//marker4 | |
var sanjosefamilyshelter = new google.maps.LatLng(37.36608, -121.86866); | |
var contentString4 = '<div>'+ | |
'<h4 id="firstHeading" class="firstHeading">San Jose Family Shelter</h4>'+ | |
'<div id="bodyContent">'+ | |
'<p><b>San Jose Family Shelter</b>' + | |
', 692 N. King Road, 95133, San Jose. '+ | |
' Near the Fair Oaks / Wolfe Road split, '+ | |
' 408.926.8885, '+ | |
' '+ | |
'Call between 10:00am and 11:00am M-F for availability. '+ | |
'Program fee. '+ | |
'Parents over 18 & boys up to 17 years. '+ | |
'Comprehensive day services, monthly bus passes.'+ | |
'</div>'+ | |
'</div>'; | |
var infowindow4 = new google.maps.InfoWindow({ | |
content: contentString4 | |
}); | |
var marker4 = new google.maps.Marker({ | |
position: sanjosefamilyshelter, | |
draggable:false, | |
title:"Centre" | |
}); | |
//sets marker on map | |
marker4.setMap(map); | |
google.maps.event.addListener(marker4, 'click', function() { | |
infowindow4.open(map,marker4); | |
}); | |
//end of marker 4 | |
//marker5 | |
var innvision1 = new google.maps.LatLng(37.33684, -121.90413); | |
var contentString5 = '<div>'+ | |
'<h4 id="firstHeading" class="firstHeading">InnVision Emergency and Transitional Shelter</h4>'+ | |
'<div id="bodyContent">'+ | |
'<p><b>InnVision Emergency and Transitional Shelter</b>' + | |
', Montgomery Street Inn, 358 N Montgomery St., '+ | |
' San Jose, CA 95110, '+ | |
' 408.271.5160, '+ | |
' '+ | |
'Arrive by 10:00am Monday-Friday for assessment for program entry. '+ | |
'Adult Men Only. '+ | |
'</div>'+ | |
'</div>'; | |
var infowindow5 = new google.maps.InfoWindow({ | |
content: contentString5 | |
}); | |
var marker5 = new google.maps.Marker({ | |
position: innvision1, | |
draggable:false, | |
title:"Centre" | |
}); | |
//sets marker on map | |
marker5.setMap(map); | |
google.maps.event.addListener(marker5, 'click', function() { | |
infowindow5.open(map,marker5); | |
}); | |
//end of marker 5 | |
//marker6 | |
var innvision2 = new google.maps.LatLng(37.35997, -121.90075); | |
var contentString6 = '<div>'+ | |
'<h4 id="firstHeading" class="firstHeading">InnVision Emergency and Transitional Shelter</h4>'+ | |
'<div id="bodyContent">'+ | |
'<p><b>InnVision Emergency and Transitional Shelter</b>' + | |
', Commercial Street Inn, '+ | |
' 260 Commercial Street, '+ | |
' San Jose, CA 95112'+ | |
' Call 408.271.1630 for availability. '+ | |
' Adult Women Only. '+ | |
'</div>'+ | |
'</div>'; | |
var infowindow6 = new google.maps.InfoWindow({ | |
content: contentString6 | |
}); | |
var marker6 = new google.maps.Marker({ | |
position: innvision2, | |
draggable:false, | |
title:"Centre" | |
}); | |
//sets marker on map | |
marker6.setMap(map); | |
google.maps.event.addListener(marker6, 'click', function() { | |
infowindow6.open(map,marker6); | |
}); | |
//end of marker 6 | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); |
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 | |
$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 | |
"infoWindow1", //10 | |
"content1", //11 | |
"location1", //12 | |
"marker1", //13 | |
), | |
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 | |
"infoWindow2", //10 | |
"content2", //11 | |
"location2", //12 | |
"marker2", //13 | |
), | |
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