0
我有兩個位置(標記)要顯示在谷歌地圖上,一個是名爲「companyLocale」的靜態變量。第二個是基於您當前位置「initialLocation」的動態變量。我試圖將它們分組到一個名爲「localArray」的數組中,但我無法獲取「companyLocale」變量以在數組內顯示。有人可以幫幫我嗎?具有靜態變量的地理位置數組
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: iPhone Geolocation</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var initialLocation;
var companyLocale = new google.maps.LatLng(33.206060, -117.111951);
var localArray = [initialLocation,companyLocale];
var noGeo = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
function initialize() {
var myOptions = {
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
// Safari supports the W3C Geolocation method
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
var placeMarker = new google.maps.Marker({
position: initialLocation,
map: map,
});
map.setCenter(initialLocation);
}, function() {
handleNoGeolocation(browserSupportFlag);
});
} else {
// Browser doesn't support Geolocation
handleNoGeolocation();
}
function handleNoGeolocation() {
initialLocation = noGeo;
map.setCenter(initialLocation);
}
}
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
鄧肯,謝謝你的迴應,我試了上面的代碼,但結果沒有改變。我仍然只獲取initialLocation變量來顯示,localArray仍然不會出現。請你再幫忙嗎? – need2nobasis
那麼在代碼中,你沒有對localArray做任何事情,你是什麼意思「localArray仍然不會出現」 - 出現在哪裏/如何? – duncan
我試圖在數組中獲取變量initialLocation和companyLocale,並使該數組中的每個變量都基於座標顯示在地圖上作爲標記。 – need2nobasis