几乎完全遵循以下代码:https://developers.google.com/maps/documentation/javascript/places#TextSearchRequests
当
service = new google.maps.places.PlacesService(map);
调用,控制台给我一个未定义的类型错误:
util.js:22 Uncaught TypeError: Cannot read property 'innerHTML' of undefined
我的代码如下。有谁知道发生了什么事?
HTML
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDo5LxyVUv5EwGQBwaveIF4d0MaIVD_Dd8&libraries=places"></script>
JS
function initMap(userLocation) {
map = new google.maps.Map(document.getElementById('map'), {
center: userLocation,
zoom: radius
});
infowindow = new google.maps.InfoWindow();
}
function textSearch(query) {
var service;
var request = {
location: userLocation,
query: query
};
service = new google.maps.places.PlacesService(map);
service.textSearch(request, cb);
}
function cb(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
// createMarker(results[i]);
console.log(place);
}
}
}
initMap(userLocation); // userLocation is a latLong obj, set elsewhere in the code.
textSearch('movies');