I am trying to display google map using backbonejs below.
define([
'require',
'backbone',
'text!../templates/list.html',
], function(Require, Backbone, Template){
return Backbone.View.extend({
tagName: 'div',
template: _.template(Template),
initialize: function(){
this.render();
},
render: function(){
var self = this;
this.$el.html(this.template());
self.initMap();
},
initMap: function(){
var target = { lat: 1.098706, lng: 104.026971 };
var mapOption = {zoom: 12, center: target };
var mapElem = $(".container").find("#map-canvas");
var map = new google.maps.Map(mapElem, mapOption);
var marker = new google.maps.Marker({
position: target,
map: map
});
},
});
});
After render finish, I got this error:
Uncaught TypeError: Cannot set property 'position' of undefined
I am still confused about where 'position' came from. I've tried some solutions from here and here
Have you some ideas to fix it? Thanks.