我試圖從該圖「模擬」的代碼:簡單地址解析器
https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple
僅改變Syney到阿雷格里港(形式值和座標以及)。但是由於地圖畫布沒有顯示在屏幕上,所以出現了問題。我檢查了代碼,沒有發現任何錯字或語法錯誤。
我希望有人能幫忙。實際上,我比Google Maps API更多地使用Fusion Tables。
<!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>GEOCODER</title>
<link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
<script src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script>
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-30.027704, -51,228735);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
);
}
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width: 320px; height: 480px;"></div>
<div>
<input id="address" type="textbox" value="Porto Alegre, Brasil">
<input type="button" value="Encode" onclick="codeAddress()">
</div>
</body>
</html>
非常感謝,男人!現在地圖工作正常!我認爲使用'代碼編輯器'就足夠了。 JavaScript控制檯將是Firebug? – 2012-07-31 01:58:00
Firebug提供訪問控制檯,是的。但是每個現代瀏覽器都內置了一個瀏覽器。確實值得研究如何看待它。這對調試至關重要。 – Trott 2012-07-31 02:55:09