Created
August 22, 2016 00:12
-
-
Save openqubit/292872006f029b431003422749ce397a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Template.NotFound.onCreated(function () { | |
GoogleMaps.ready('map2', function(map2) { | |
google.maps.event.addListener(map2.instance, 'click', function(event) { | |
Markers.insert({ lat: event.latLng.lat(), lng: event.latLng.lng() }); | |
}); | |
var markers = {}; | |
Markers.find().observe({ | |
added: function (document) { | |
var marker = new google.maps.Marker({ | |
draggable: true, | |
animation: google.maps.Animation.DROP, | |
position: new google.maps.LatLng(document.lat, document.lng), | |
map: map2.instance, | |
id: document._id | |
}); | |
google.maps.event.addListener(marker, 'dragend', function(event) { | |
Markers.update(marker.id, { $set: { lat: event.latLng.lat(), lng: event.latLng.lng() }}); | |
}); | |
markers[document._id] = marker; | |
}, | |
changed: function (newDocument, oldDocument) { | |
markers[newDocument._id].setPosition({ lat: newDocument.lat, lng: newDocument.lng }); | |
}, | |
removed: function (oldDocument) { | |
markers[oldDocument._id].setMap(null); | |
google.maps.event.clearInstanceListeners(markers[oldDocument._id]); | |
delete markers[oldDocument._id]; | |
} | |
}); | |
}); | |
var self = this; | |
GoogleMaps.ready('map', function(map) { | |
var marker; | |
// Create and move the marker when latLng changes. | |
self.autorun(function() { | |
var latLng = Geolocation.latLng(); | |
if (! latLng) | |
return; | |
// If the marker doesn't yet exist, create it. | |
if (! marker) { | |
marker = new google.maps.Marker({ | |
position: new google.maps.LatLng(latLng.lat, latLng.lng), | |
map: map.instance | |
}); | |
} | |
// The marker already exists, so we'll just change its position. | |
else { | |
marker.setPosition(latLng); | |
} | |
// Center and zoom the map view onto the current position. | |
map.instance.setCenter(marker.getPosition()); | |
map.instance.setZoom(MAP_ZOOM); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment