I have a map where I need to place markers. I've created a collection in MongoDB and have a sample data set ready for the marker. However, I am having trouble retrieving the data and actually creating the marker on the map.
The Map
Meteor.startup(function() {
GoogleMaps.load();
});
Template.map.helpers({
mapOptions: function() {
if (GoogleMaps.loaded()) {
return {
center: new google.maps.LatLng(-37.8136, 144.9631),
zoom: 8
};
}
}
});
Template.map.helpers({
marker: function() {
return MarkerData.find();
}
});
Creating Markers
for (var i = 0; i < MarkerData.length; i++) {
var lat = {{ lat }}
var lng = {{ lng }}
var title = {{ title }}
var address = {{ address }}
var url = {{ url }}
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map: map,
title: title,
animation: google.maps.Animation.DROP,
});
}
My Collection
MarkerData = new Mongo.Collection('markerdata');
Data within the Collection
if (MarkerData.find().count() === 0) {
MarkerData.insert({
lat: 34.200659,
lng: -118.519986,
title: 'Extensions Plus HQ',
address: '17738 Sherman Way Reseda, CA 91335',
url: 'http://extensionsplus.com'
});
}
I will continue adding more data into the collection. This is just a test to ensure the code works properly.