script.php?q=canada
에 응답하고지도를 보여주는 간단한 GoogleMap을 작성했습니다.지오 코딩이 포함 된 간단한 Google지도
하나의 문제는 항상 두 번째의 중심 var latlng = new google.maps.LatLng(34.052234,-118.243685);
와지도를로드 한 다음 오른쪽지도를로드합니다. 내 코드를 잘못 무엇
?
<!DOCTYPE html>
<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><?=$_GET['q']?></title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(34.052234,-118.243685);
var address = '<?=$_GET['q']?>';
var myOptions = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
// autozoom
map.fitBounds(results[0].geometry.viewport);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title: 'by Quick Maps',
clickable: false
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
</body>
</html>
Sidequestion : 방법지도에 간단한 메시지와 함께 alert("Geocode was not successful for the following reason: " + status);
를 대체?
'결과 [0]은 google.maps.LatLng 객체가 .geometry.location'. '.Pa'와'.Qa' 대신'results [0] .geometry.location.lat()'와'results [0] .geometry.location.lng()'을 사용해야합니다. 그리고 가지고있다). –
고마워, 나는 대답을 고쳤다 :) –