我正在尝试创建一个具有不同位置的地图,我正在使用knockout绑定在我的html视图上显示一些功能。 我有一个功能,使我能够创建各种位置。
我希望每个位置都有自己的标记。渲染地图时,我会显示一些默认位置。但我有这个错误:未捕获的ReferenceError:谷歌未定义
这是我的代码。
defaultMarkers =[
new Locations("Ike's Food & Cocktails","(612) 746-4537","50 S 6th St","",44.97818705436708,-93.27229499816895),
new Locations("Eli's East Food & Cocktails","(612) 331-0031","815 E Hennepin Ave","#",44.99128282822349,-93.24738264083862),
new Locations("Midnord Empanada Food truck","unavailable","unavailable","#",44.97596890779807,-93.27159452192403),
new Locations("Maruso Street Food Bar","(612) 333-0100", "715 E Hennepin Ave","#",44.97760063074655,-93.2754345812601),
new Locations("The House Of Hunger Food Truck","unavailable","unavailable","#",44.97611524414878,-93.27146677068872)];
var map;
function initMap() {
var mapOptions = {
center: {lat: 38.9165087, lng: -77.2482606},
zoom: 13
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
// add defaults markers on map
updateMap(map, defaultMarkers);
}
function Locations(name, contact, fulladress, url, lat, lng){
var self = this;
self.name= name;
self.contact = contact;
self.url = url;
self.fulladress = fulladress;
self.lat = lat;
self.lng = lng;
self.showMe = ko.observable(true);
self.marker = new google.maps.Marker({ // HERE IS THE LINE WHERE THE ERROR OCCUR
position: new google.maps.LatLng(lat, lng),
map: map,
});}
function MapViewModel() {
var self = this;
self.listVenues = ko.observableArray(defaultMarkers);
}
你能帮我弄清楚我做错了吗?
。
答案 0 :(得分:0)
确保您的脚本是:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&key=APIKEY"></script>
不包括type="text/javascript"
可能会搞砸你。