내가 같은 일을 할 필요가
if(navigator.geolocation) {
navigator.geolocation.watchPosition(function(position) {
var pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
은} 그래서 모의 하나로 navigator.geolocation 객체를 대체 할 테스트 스크립트를 썼다. 여기 내 코드는 다음과 같습니다
// Replace real geolocation with mock geolocation
delete navigator.geolocation;
navigator.geolocation = {
isMock: true,
paused: true,
delay: 100,
shouldFail: false,
failsAt: -1,
unFailsAt: -1,
errorMessage: "There was an error retrieving the position!",
currentTimeout: -1,
lastPosReturned: 0,
overrideAccuracy: 0, // accuracy in m to return for all positions (overrides any existing accuracies defined in the waypoints)
useOverrideAccuracy: false, // Whether to override acurracies defined in the waypoints with the above override accuracy
_geoCall: function(method, success, error, repeat) {
return this.currentTimeout = window[method].call(null, __bind(function() {
var nextPos;
if(!this.paused && this.lastPosReturned < this.waypoints.length - 1){
nextPos = this.lastPosReturned++;
}else{
this.lastPosReturned = nextPos = 0;
}
if(!this.shouldFail && nextPos == this.failsAt) this.shouldFail = true;
if(this.shouldFail && nextPos == this.unFailsAt) this.shouldFail = false;
if(repeat) this._geoCall("setTimeout", success, error, true);
if (this.shouldFail && (error != null)) {
return error(this.errorMessage);
}
else if (success != null && !this.paused) {
var result = this.waypoints[nextPos];
result.isMock = true;
if(this.useOverrideAccuracy) result.coords.accuracy = this.overrideAccuracy;
success(result);
return nextPos;
}
}, this), this.delay);
},
getCurrentPosition: function(success, error) {
return this._geoCall("setTimeout", success, error, false);
},
watchPosition: function(success, error) {
this._geoCall("setTimeout", success, error, true);
return this.currentTimeout;
},
clearWatch: function(id) {
return clearInterval(this.currentTimeout);
},
waypoints: []
};
그럼 난 그냥 위치 물체로 navigator.geolocation.waypoints 배열을 채울 필요가있다.
watchPosition을 사용하여 자신의 위치를 추적 한 다음 동일한 기능을 사용하여 다른 사람의 위치를 보려고했는데 배열에서 좌표가 제공 되었기 때문입니다. – Kayoti
"실제"위치 업데이트와 모의 위치 업데이트를 동시에 받고 싶습니까? 위 코드를 모의 위치 업데이트에 사용할 수 있지만 navigator.mockGeolocation으로 이름을 바꿉니다. 그런 다음 실제 위치 (navigator.geolocation.watchPosition)와 모의 위치 (navigator.mockGeolocation.watchPosition)를 동시에 볼 수 있습니다. – DaveAlden
고맙습니다 – Kayoti