实时地理定位离子

Hou*_*sem 3 leaflet ionic-framework

我想用离子构建移动应用程序,首先用户是地理位置我想每2秒更新一次他的位置这是地理位置的代码

$scope.makeFit = function() {
  leafletData.getMap().then(function(map) {
    map.locate({setView: true, maxZoom: 16});
    var marker;
    function onLocationFound(e) {
      marker= new L.Marker(e.latlng);
      marker.addTo(map)
            .bindPopup("" + e.latlng + " ");
    }
    map.on('locationfound', onLocationFound); 
  });
};
Run Code Online (Sandbox Code Playgroud)

tmc*_*mcw 5

阅读Leaflet参考文档,该文档记录了将执行此操作的watch选项locate().