経度と緯度をGoogleMapsJavaScriptV3APIに渡そうとしています。以下の私のコードは、スイッチからgoogleLatLong変数を取得し、それをGoogle initialize()関数に渡す必要があります。ただし、現時点では、initialize()関数でgoogleLatLong変数にアクセスすることはできません。どうすれば通過できますか?
前もって感謝します。
頭の中のJavaScript:
<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:
<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>