2015-11-05 85 views
0

我正在嘗試創建谷歌地圖。這張地圖應該保持中心,永不移動。我正在創建實時跟蹤,但我遇到跟蹤問題。每隔幾秒,跟蹤功能就會每隔幾秒刷新一次頁面。Google地圖定位刷新頁面

.controller('mapCtrl', function ($scope, $ionicSideMenuDelegate, $ionicLoading, $compile, $ionicPopup, $cordovaGeolocation) { 

$ionicSideMenuDelegate.canDragContent(false); 
var onSuccess = function(position) { 


    var myLatlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 
    var CSUS_CENTER = (38.55914, -121.423473); 

      var mapOptions = { 
       center: CSUS_CENTER, 
       zoom: 16, 
       mapTypeId: google.maps.MapTypeId.ROADMAP, 
       zoomControl: true, 
       disableDefaultUI: true 
      }; 
      var map = new google.maps.Map(document.getElementById("map"), 
       mapOptions); 

      //Marker + infowindow + angularjs compiled ng-click 
      var contentString = "<div><a ng-click='clickTest()'>Click me!</a></div>"; 
      var compiled = $compile(contentString)($scope); 

      var infowindow = new google.maps.InfoWindow({ 
       content: compiled[0] 
      }); 

      var marker = new google.maps.Marker({ 
       position: myLatlng, 
       map: map, 
       title: 'Sac State' 
      }); 

      google.maps.event.addListener(marker, 'click', function() { 
       infowindow.open(map, marker); 
      }); 

      $scope.map = map; 
      $scope.map.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude)); 
}; 

// onError Callback receives a PositionError object 
// 
function onError(error) { 
    alert('code: ' + error.code + '\n' + 
      'message: ' + error.message + '\n'); 
} 

navigator.geolocation.watchPosition(onSuccess, onError, {maximumAge: 3000, timeout: 5000, enableHighAccuracy: true }); 

}); 

所以,我的問題是,地圖recenters每次刷新的時間,我想保持它爲中心在原來的緯度和經度。那麼其他的問題是,網頁會freshing

回答

2

如果你只需要獲得位置一次,使用getCurrentPosition,不watchPosition

+0

改變watchPoistion到getCurrentPosition並從清爽阻止它,但我需要它太contentiously跟蹤我 –