2012-09-27 342 views
1

我使用谷歌地點api。這是我的代碼,它運行良好,但當ı刷新頁面過了一段時間過去螢火蟲一直給我這個錯誤google.maps.event是undefined谷歌地圖地方api

我期待Firebug的Net選項卡,我看到GET JS?傳感器=假&庫=地方中止maps.googleapis.com

我怎樣才能解決這個問題?

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>

var map; 
    var infowindow; 

    function initialize() { 
    var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316); 

    map = new google.maps.Map(document.getElementById('mapCanvas'), { 
     mapTypeId: google.maps.MapTypeId.ROADMAP, 
     center: pyrmont, 
     zoom: 15 
    }); 


    var request = { 
     location: pyrmont, 
     radius: 500, 
     types: ['school'] 
    }; 
    infowindow = new google.maps.InfoWindow(); 
    var service = new google.maps.places.PlacesService(map); 
    service.search(request, callback); 
    } 

    function callback(results, status) { 
    if (status == google.maps.places.PlacesServiceStatus.OK) { 
     for (var i = 0; i < results.length; i++) { 
     createMarker(results[i]); 
     } 
    } 
    } 

    function createMarker(place) { 
    var placeLoc = place.geometry.location; 
    var marker = new google.maps.Marker({ 
     map: map, 
     position: place.geometry.location 
    }); 

    google.maps.event.addListener(marker, 'click', function() { 
     infowindow.setContent(place.name); 
     infowindow.open(map, this); 
    }); 
    } 

    google.maps.event.addDomListener(window, 'load', initialize); 

回答

1

谷歌建議您始終使用在腳本標記的src屬性中提到的網址的谷歌API密鑰。

JS?傳感器=假&庫=地方& 鍵= XXXXXXXXXXXXXXXX

請嘗試,讓我知道。

問候

戈文達拉揚

+0

感謝它的工作:) – gokhan04186