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