尝试将自动填充功能添加到我的Google地图时出现以下错误:google is not defined
。我正在使用Meteor包dburles:google-maps
来实现。
这是我的代码
html的
<template name="search">
{{> map}}
<div class="container">
<div class="search">
<form>
<label for="location">Location</label>
<input id="search" type="text">
</form>
</div>
</div>
</template>
的.js
// Loading map on startup
Meteor.startup(function() {
GoogleMaps.load({ key: 'API-KEY', libraries: 'places' });
var autoComplete = new google.maps.places.Autocomplete(
document.getElementById(search), {
types: ['(cities)']
});
google.maps.event.addListener(autoComplete, 'place_changed', function() {
var place = autocomplete.getPlace();
if (place.geometry) {
map.panTo(place.geometry.location);
map.setZoom(15);
}
});
});
Template.map.helpers({
locationsOptions: function() {
// Make sure the maps API has loaded
if (GoogleMaps.loaded()) {
// Map initialization options
return {
center: new google.maps.LatLng(52.524268, 13.406290),
zoom: 12
};
}
}
});
Template.map.onCreated(function() {
// We can use the `ready` callback to interact with the map API once the map is ready.
GoogleMaps.ready('locations', function(map) {
// Add a marker to the map once it's ready
var marker = new google.maps.Marker({
position: map.options.center,
map: map.instance
});
});
});
可能出现错误的任何想法?