空白屏幕Google Maps API V3

时间:2013-05-09 12:29:27

标签: maps geocoding

正如标题所说,我在尝试将地理编码功能添加到地图时只有空白屏幕。如果我单独使用标记离开地图,它可以正常工作。但是,在我添加地理编码功能的那一刻,它只是给我发送一个空白屏幕。这是代码:

<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 API v3: esempio base</title>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">

<script type="text/javascript">
var initialize = function() {


var latlng = new google.maps.LatLng(42.745334,12.738430);


var options = { zoom: 12,
              center: latlng,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            };


var map = new google.maps.Map(document.getElementById('map'), options);


var marker = new google.maps.Marker({ position: latlng,
  map: map, 
  title: 'W Le DONNE' });


 var createMap = function() {
   searchAddress();
    var address = document.getElementById("address").value;
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode( {'address': address}, function(results,status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var options = {
                zoom: 12,
                center: results[0].geometry.location,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
        else {
            alert("Problema nella ricerca dell'indirizzo: " + status);
        }
    });
}
var searchAddress = function(){
    document.getElementById("submit").onclick = function() {
        createMap();
    }

}}

window.onload = createMap;
</script>

</head>
<body style="margin:0; padding:0;">
<div>
<input id="address" type="textbox" value="Viale Franco Angeli, 5 - Roma">
<input id="submit" type="button" value="trova indirizzo sulla mappa">
</div>
<div id="map" style="width:100%; height:100%"></div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您的网址错误。 V3是http://maps.googleapis.com/maps/api/js