I am trying to pass a longitude and latitude to Google Maps JavaScript V3 api. My code as below should take the googleLatLong variable from the switch and then pass it to the Google initialize() function. However at the moment the googleLatLong variable is not accessible in the initialize() function. How do I pass it through?
Thanks in advance.
JavaScript in the head:
<script type="text/javascript">
//function to get a parameter from the query string
var queryString = function(){
var s = window.location.search.substr(1),
p = s.split(/\&/),
l = p.length,
kv, r = {};
if(l === 0){return false;}
while(l--){
kv = p[l].split(/\=/);
r[kv[0]] = kv[1] || true;
}
return r;
}();
//get params from the url
var storeCode = queryString.store;
//switch page params based on the store code
switch(storeCode) {
case 'POO746':
var storeName = 'Poole';
var googleLatLong = '50.736129,-1.988229';
var trafficURL = 'http://hatrafficinfo.dft.gov.uk/feeds/rss/CurrentAndFutureEvents/South%20West.xml';
break;
case 'BRS464':
var storeName = 'Bognor Regis';
var googleLatLong = '50.798991,-0.667444';
var trafficURL = 'http://hatrafficinfo.dft.gov.uk/feeds/rss/CurrentAndFutureEvents/South%20East.xml';
break;
}
</script>
JavaScript in the body:
<script type="text/javascript">
var map
function initialize() {
var store = new google.maps.LatLng(googleLatLong);
var myOptions = {
zoom:12,
mapTypeId: google.maps.MapTypeId.HYBRID,
disableDefaultUI: true,
center: store
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
}
window.onload = function () {
initialize();
}
</script>
<div id="trafficMap">
<div id="map_canvas"></div>
</div>