我正在使用谷歌的地方api。这是我的代码,它运行良好但是当fire刷新页面后,过去firebug已经给我这个错误 google.maps.event未定义。
look看看firebug的网络标签ı看到 GET js?sensor = false& libraries = places Aborted 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);
答案 0 :(得分:1)
Google建议您始终在脚本代码的src属性中提到的网址中使用Google API密钥。
?JS传感器=假安培;库=地方&安培;的键= XXXXXXXXXXXXXXXX 强>
请尝试并告诉我。
此致
戈文达拉扬