자바 스크립트에서 사용자 위치를 수집하는 응용 프로그램을 작성하려고합니다. 현재 Geolocation API를 사용하여 랩톱에서 디버깅 중이며 주어진 시간 동안 작동하는 것으로 입증되었습니다. 몇 초마다 내 위치를 브로드 캐스트 한 다음 5-10 초 후에 이동할 때 다시 계산됩니다. 이것은 어떤 이유로 든 내 배터리/CPU를 많이 사용하는 것으로 입증되었습니다. 이 앱을 휴대 전화에서 사용하려면 GPS를 통해 내 위치를 방송하거나 로컬 기지국에서 위치를 삼각 측량 할 것인가?휴대 전화의 삼각 측위 위치 대 GPS
var latitude, longitude, accuracy, angle;
function setGeolocation(prevID) {
var geoID = window.navigator.geolocation.watchPosition(getPosition,handleErrors,{maximumAge: 1000, enableHighAccuracy: true});
//Pass the ID's to the seeMyGeoID function.
seeMyGeoID(geoID,prevID);
function getPosition(position){
latitude = position.coords.latitude;
longitude = position.coords.longitude;
accuracy = position.coords.accuracy;
angle = position.coords.heading;
console.log(latitude+" "+longitude+" "+accuracy+" "+angle);
};
function handleErrors(err){
if (err.code == 1){
console.log("PERMISSION_DENIED");
}
if (err.code == 2){
console.log("POSITION_UNAVAILABLE");
}
if (err.code == 3){
console.log("TIMEOUT");
}
};
};
function seeMyGeoID(geolocationID,previousID){
if(geolocationID != previousID){
previousID = geolocationID;
//Wait 1 second.
setTimeout(function(){
navigator.geolocation.clearWatch(previousID);
navigator.geolocation.clearWatch(previousID+1);
setGeolocation(previousID);
},1000);
}
};
//Call function for the first time.
setGeolocation(0);
//I want this code to be able to take a position every 0.5-1 second, or in real time (but that may be pushing it).
그건 의미가 있습니다. 아직 전화에서 디버깅/테스트 할 수있는 기능이 없습니다. 나는 컴파일을 속도와 배터리 수명이 부담이되지 않도록 첫 번째 선택으로 GPS를 사용하도록 구현을 지시하는 방법을 이해하려고 노력하고있다. 고마워, 첸. – Sam