Google지도에 표시 할 위치 (마커)가 두 개 있습니다. 하나는 "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>
Duncan, 응답 해 주셔서 감사합니다. 위 코드를 시도했지만 결과는 변경되지 않았습니다. 여전히 initialLocation 변수 만 표시하면 localArray는 표시되지 않습니다. 이걸 다시 도울 수 있겠 니? – need2nobasis
localArray에서 아무 것도하지 않는 코드에서 "localArray가 여전히 나타나지 않습니다"라는 의미는 무엇입니까? – duncan
배열에서 변수 initialLocation과 companyLocale을 모두 가져 오려고 시도하고 해당 배열 내의 각 변수를 좌표에 따라 마커로 매핑에 표시하려고했습니다. – need2nobasis