As in my posed question, I needed some help to integrate the functions of Google Maps. The question has not been given so far, and I want you to briefly describe how to solve this problem.
How to integrate cards in meteor.js / meteorite.js?
First you must include the map script in your header
<head> .... <title>Meteor and Google</title> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script> </head>
How should you create a template card:
<template name="mapPostsList"> <div id="map"> <div id="map-canvas"></div> </div> </template>
In the associated js file, you must define a render function. When the rendered function is called, you create a map and display a marker on the map. (Remember to give you a css map)
Template.mapPostsList.rendered = function() { var mapOptions = { zoom: 12, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); var p2 = Session.get('location'); map.setCenter(new google.maps.LatLng(p2.lat, p2.lng)); var marker = new google.maps.Marker({ position: new google.maps.LatLng(p2.lat, p2.lng), title:'Meine Position', icon:'http://maps.google.com/mapfiles/ms/icons/blue-dot.png' }); marker.setMap(map); Session.set('map', true); };
Now, object cards are recreated every time a template is displayed. This is not the best practice, but it works. I tried putting the creation in Template.mapPostsList.created-callback, but it always causes an offset width error. How do I set a marker with my position on the map and determine the session that is initialized by my map.
Well. But now my session is initializing on the first rendering, so I set it to false when my template is destroyed.
Template.mapPostsList.destroyed = function() { Session.set('map', false); };
If you want to receive your messages on the card, you need to define the autorun function.
Deps.autorun(function() { var isMap = Session.get('map'); if(isMap) { var allPosts = Posts.find(); allPosts.forEach(function (post) { var marker = new google.maps.Marker({ position: new google.maps.LatLng(post.location.lat, post.location.lng), title: post.title, postId: post._id }); marker.setMap(map); }); } });
The Deps.autorun function always runs if the content changes. This means that if I change my session map variable, autostart is called. If I set it to false, I do nothing. Else I take all my messages to the map within forEach. Due to the recreation of the map during rendering, I donβt need to check which messages are already marked on the map when changing my collection.
This solution works well for me.
Hope I can help with this!