2015-06-30 53 views
0

我正在使用Meteor dburles:maps包,並試圖從Google Maps API實現geolocation功能,但似乎無法找到如何解決此問題的方法。我有以下的JS和HTML結構:Meteor dburles:地圖包添加地理位置

的.html

<template name="map"> 
    <div class="map-container"> 
    {{> googleMap name="map" options=mapOptions}} 
    </div> 
    <div class="container"> 
    <div class="search"> 
     <input id="search" type="text"> 
    </div> 
    </div> 
</template> 

的.js

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

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

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

    if(navigator.geolocation) { 
     // Support 
    } else { 
     // No support 
    } 

    }) 
}) 

我想我必須與Template.map.onCreated內的API進行交互,但我似乎無法弄清楚究竟要添加什麼。我已經看過谷歌地圖文檔,但結構不同,因爲有些東西是軟件包在引擎蓋下。任何遇到過這個問題並解決了它的人?

+0

你想解決什麼問題? – Yaniv

+0

插入地理位置,以便地圖加載用戶的當前位置。 –

回答

0

首先,您要添加所需的軟件包:

meteor add mdg:geolocation 

更改的MapOptions助手到:

Template.map.helpers({ 
    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 
     }; 
    } 
    } 
});