-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgooglemaps-geolocation.js
More file actions
55 lines (48 loc) · 1.39 KB
/
googlemaps-geolocation.js
File metadata and controls
55 lines (48 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
if (Meteor.isClient) {
var MAP_ZOOM = 15;
Meteor.startup(function() {
GoogleMaps.load();
});
Template.map.onCreated(function() {
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);
});
});
});
Template.map.helpers({
geolocationError: function() {
var error = Geolocation.error();
return error && error.message;
},
mapOptions: function() {
var latLng = Geolocation.latLng();
// Initialize the map once we have the latLng.
if (GoogleMaps.loaded() && latLng) {
return {
center: new google.maps.LatLng(latLng.lat, latLng.lng),
zoom: MAP_ZOOM
};
}
}
});
}