Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. Places = new Mongo.Collection('places');
  2. var loc;
  3. var pyrmont;
  4. if (Meteor.isClient) {
  5. var lookup = [];
  6.  
  7. Meteor.startup(function() {
  8. GoogleMaps.load({key: "AIzaSyACgaDFJrh2pMm-bSta1S40wpKDDSpXO2M"
  9. , libraries: 'geometry, places'});
  10.  
  11.  
  12.  
  13.  
  14. // success callback
  15. function success(position) {
  16. Session.set('latitude', position.coords.latitude);
  17. Session.set('longitude', position.coords.longitude);
  18. };
  19.  
  20. // error callback
  21. function error(err) {
  22. console.warn('ERROR(' + err.code + '): ' + err.message);
  23. };
  24.  
  25. // geolocation options
  26. var options = {
  27. enableHighAccuracy: true,
  28. timeout: 5000,
  29. maximumAge: 0
  30. };
  31.  
  32. // now try to get the user's position
  33. navigator.geolocation.getCurrentPosition(success, error, options);
  34.  
  35. // grab location
  36. loc = {
  37. lat: Session.get('latitude'),
  38. lng: Session.get('longitude')
  39. };
  40.  
  41. console.log("Your lat is: "+loc.lat);
  42. console.log("Your lng is: "+loc.lng);
  43. });
  44.  
  45.  
  46.  
  47. Template.map.onCreated(function() {
  48. var self = this;
  49.  
  50. GoogleMaps.ready('map', function(map) {
  51. self.autorun(function() {
  52. getBox();
  53.  
  54. var handle = Meteor.subscribe('places', Session.get('box'));
  55. if (handle.ready()) {
  56. var places = Places.find().fetch();
  57.  
  58. _.each(places, function(place) {
  59. var lat = place.location.coordinates[0];
  60. var lng = place.location.coordinates[1];
  61.  
  62. if (!_.contains(lookup, lat+','+lng)) {
  63. var marker = new google.maps.Marker({
  64. position: new google.maps.LatLng(lat, lng),
  65. map: GoogleMaps.maps.map.instance
  66. });
  67. lookup.push(lat+','+lng);
  68. }
  69. });
  70. }
  71. });
  72.  
  73. google.maps.event.addListener(map.instance, 'dragend', function(e){
  74. getBox();
  75. });
  76.  
  77. google.maps.event.addListener(map.instance, 'zoom_changed', function(e){
  78. getBox();
  79. });
  80. });
  81. });
  82.  
  83. Template.map.helpers({
  84. mapOptions: function() {
  85. if (GoogleMaps.loaded()) {
  86. var newMap=new google.maps.LatLng(loc.lat, loc.lng);
  87. var service=new google.maps.places.PlacesService(map);
  88. return {
  89. center: newMap,
  90. zoom: 14
  91. };
  92. }
  93. },
  94.  
  95. doThis: function(){
  96. if(GoogleMaps.loaded()){
  97. console.log("HERE");
  98. pyrmont=new google.maps.LatLng(loc.lat,loc.lng);
  99. map = new google.maps.Map(document.getElementById('map'), {
  100. center: pyrmont,
  101. zoom: 15
  102. });
  103.  
  104. service.textSearch(request, callback);
  105.  
  106.  
  107. function callback(results, status) {
  108. if (status == google.maps.places.PlacesServiceStatus.OK) {
  109. for (var i = 0; i < results.length; i++) {
  110. var place = results[i];
  111. console.log(results[i]);
  112. }
  113. }
  114. }}},
  115.  
  116. places: function() {
  117. return Places.find();
  118. }
  119. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement