Javascript 谷歌地图地理位置刷新页面
我正在尝试创建一个谷歌地图。这张地图应该居中,永远不要移动。我正在创建实时跟踪,但跟踪有问题。跟踪功能每隔几秒钟刷新一次页面Javascript 谷歌地图地理位置刷新页面,javascript,google-maps,geolocation,apache-cordova,Javascript,Google Maps,Geolocation,Apache Cordova,我正在尝试创建一个谷歌地图。这张地图应该居中,永远不要移动。我正在创建实时跟踪,但跟踪有问题。跟踪功能每隔几秒钟刷新一次页面 .controller('mapCtrl', function ($scope, $ionicSideMenuDelegate, $ionicLoading, $compile, $ionicPopup, $cordovaGeolocation) { $ionicSideMenuDelegate.canDragContent(false); var onSucc
.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 });
});
.controller('mapCtrl',函数($scope、$ionicSideMenuDelegate、$ionicLoading、$compile、$ionicPopup、$cordovaGeolocation){
$ionicSideMenuDelegate.canDragContent(false);
var onSuccess=函数(位置){
var myLatlng=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
var CSUS_CENTER=(38.55914,-121.423473);
变量映射选项={
中心:CSUS_中心,
缩放:16,
mapTypeId:google.maps.mapTypeId.ROADMAP,
动物控制:对,
disableDefaultUI:true
};
var map=new google.maps.map(document.getElementById(“map”),
地图选项);
//Marker+infowindow+angularjs编译并单击
var contentString=“单击我!”;
var compiled=$compile(contentString)($scope);
var infowindow=new google.maps.infowindow({
内容:已编译[0]
});
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“Sac州”
});
google.maps.event.addListener(标记,'click',函数(){
信息窗口。打开(地图、标记);
});
$scope.map=map;
$scope.map.setCenter(新的google.maps.LatLng(position.coords.latitude,position.coords.longitude));
};
//OneError回调接收PositionError对象
//
函数onError(错误){
警报('code:'+error.code+'\n'+
'消息:'+error.message+'\n');
}
navigator.geolocation.watchPosition(onSuccess,onError,{maximumAge:3000,timeout:5000,enableHighAccurance:true});
});
所以,我的问题是地图每次刷新时都会重新居中,我希望它保持在原始纬度和经度的中心。然后另一个问题是页面保持刷新如果您只需要获取一次位置,请使用,而不是将WatchPosition更改为getCurrentPosition会阻止它刷新,但我需要它太有争议地跟踪我