Google지도 API를 사용하여 일부 지오 코딩을 수행하고 있습니다. 사용자가 주소가있는 양식을 채우고 제출 버튼을 클릭하면 지오 코딩을 수행해야하는 codeAddress() 함수가 호출되지만 작동하지 않습니다. 테스트에서 주소를 하드 코드하고 initialize()로 문서를 작성할 때 codeAddress 함수를 호출합니다. 페이지가 준비 될 때 codeAddress가 호출되면 제대로 작동하지만 onclick 스크립트에 의해 호출되면 작동하지 않습니다 (방화 광이 반환하는 오류 없음).지오 코딩 기능은 초기화되었을 때 작동하지만 onclick 스크립트에서는 작동하지 않습니다.
아무도 도와 드릴 수 있습니까? 감사
(당신이 여기에 코드를 붙여 넣을 수 있습니다 : 구글 API 키를 http://code.google.com/apis/ajax/playground/?exp=maps#map_simple을, 또는 변경)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps API Sample</title>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q"></script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
codeAddress();
}
}
function codeAddress() {
var geocoder = new GClientGeocoder();
var address = "paseo montjuic, 30, barcelona, spain";
geocoder.getLatLng(address, function(point) {
if (point) {
alert(point);
} else {
alert("Geocode was not successful");
}
});
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()" style="font-family: Arial;border: 0 none;">
<div id="map_canvas" style="width: 500px; height: 300px"></div>
<form action="" method="POST">
<!-- stuff -->
<input type="Submit" value="Submit" onclick="codeAddress();" />
</form>
</body>
</html>
그러나 codeAddress()가 onclick에서 호출 된 경우 경고가 표시됩니다. – jul
스크립트로 호출하는 방법에 따라 작동합니다. 즉 경고가 표시되어야합니다. – mauris
좋아요, 양식이 codeAddress()를 기다리지 않고 제출 될 때 페이지가 다시로드되는 것 같습니다. "return false;"와 함께 작동합니다. 감사! – jul