2015-11-05 101 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跟踪我 –