2

Hey I am using the two packages dburles:maps and mdg:geolocation and my goal is to plot the current location on a map. This is my current JS code which display's a map, but I am not sure how to proceed with it.

map.js EDITED

Meteor.startup(function() {
 GoogleMaps.load();
});

Template.map.helpers({
  mapOptions: function() {
    if (GoogleMaps.loaded()) {
      return {
        center: new google.maps.LatLng(current),
        zoom: 8
      };
    }
  }
});

Template.map.onCreated(function() {
  GoogleMaps.ready('map', function(map) {

    if (navigator.geolocation) {
      // Support
      navigator.geolocation.getCurrentPosition(function(position) {
        var current = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
      });
      map.setCenter(current);
    } else {
      // No support
      console.log("Something is wrong!")
    }

  })
})

I think I am supposed to add something in the if(navigator.geolocation and then place the value in the center: new google.maps.LatLng(), but not sure. Any ideas?

Julian Samarjiev
  • 479
  • 1
  • 8
  • 23

2 Answers2

1
Meteor.startup(function() {
    GoogleMaps.load({v: '3', key: 'yourKey'});  
});

var latLng;

Template.map.onCreated(function() {
  GoogleMaps.ready('map', function(map) {
  });
});

Template.map.helpers({
  mapOptions: function() {
    if (GoogleMaps.loaded()) {
        latLng = Geolocation.latLng();
        console.log('location ' + latLng.lat + ' ' + latLng.lng);
        return {
            center: new google.maps.LatLng(latLng.lat, latLng.lng),
            zoom: 14
        };
    }
  }
});
Rob Gordon
  • 46
  • 3
0

You're on the right track. Have you seen Google's Geolocation example?

Bennett Elder
  • 118
  • 1
  • 8
  • I have been looking at it for some time now, but I get confused because there are some things that get defined in different order given the maps package, I made an update to my code, that is somewhere in the ballpark, but not quite there yet. – Julian Samarjiev Jul 01 '15 at 20:33