Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 带有jQuery mobile、PhoneGap和谷歌地图的GPS跟踪器_Android_Jquery_Google Maps_Jquery Mobile_Cordova - Fatal编程技术网

Android 带有jQuery mobile、PhoneGap和谷歌地图的GPS跟踪器

Android 带有jQuery mobile、PhoneGap和谷歌地图的GPS跟踪器,android,jquery,google-maps,jquery-mobile,cordova,Android,Jquery,Google Maps,Jquery Mobile,Cordova,我已经为Android开发了一个带有PhoneGap的jQuery移动应用程序。现在,我需要一个GPS跟踪器。我想得到用户的位置,并将其与数据库中的一些坐标进行比较 我想知道,如果这种方法是好的,如果我应该改变一些东西,我怎么可以只显示一次消息 应用程序应每20秒检查一次位置 如果用户靠近目标(50米),他应该收到一条消息(但只有一次) $(文档).on(“pageinit”,函数(事件){ 函数userDistance(){ //等待PhoneGap加载 文件。添加的监听器(“devic

我已经为Android开发了一个带有PhoneGap的jQuery移动应用程序。现在,我需要一个GPS跟踪器。我想得到用户的位置,并将其与数据库中的一些坐标进行比较

我想知道,如果这种方法是好的,如果我应该改变一些东西,我怎么可以只显示一次消息

  • 应用程序应每20秒检查一次位置
  • 如果用户靠近目标(50米),他应该收到一条消息(但只有一次)

$(文档).on(“pageinit”,函数(事件){
函数userDistance(){
//等待PhoneGap加载
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
var-watchID=null;
//PhoneGap已经准备好了
函数ondevicerady(){
watchID=navigator.geolocation.watchPosition(onSuccess、onError、options);
//每10秒更新一次
var选项={频率:10000};
watchID=navigator.geolocation.watchPosition(onSuccess、onError、options);
}
//成功地理定位
成功时的功能(位置){
//用户位置
var loc1=新的google.maps.LatLng(position.coords.latitude,position.coords.longitude);
//目标位置
$.getJSON(“http://server:8080/getCoords,函数(数据){
var loc2=new google.maps.LatLng(数据[0]。纬度,数据[0]。经度);
//距离
var distance=google.maps.geometry.sphereal.ComputedDistanceBeween(loc1,loc2);
如果(距离<50){
警报(“目标到达”);
}
});
}
//OneError回调接收PositionError对象
函数onError(错误){
}
//每20秒看一次位置
setTimeout(用户距离,20000);
}
用户距离();
});

W/o用勺子喂代码,逻辑很简单

1) 在全局/根目录中创建一个变量=0。此变量将告诉函数是否已通知用户 2) 在警报例程中,添加以下代码

if (distance < 50 and **notified==0**) {    
            **notified=1;** // tells your app that the user has been notified already, and wont alert again
            alert("target arrived");

        }
if(距离<50且**通知==0**){
**notified=1;**//告诉您的应用程序该用户已经收到通知,并且不会再次发出警报
警报(“目标到达”);
}
3) 在检查距离例行程序中,添加距离>50时的评估,重置变量,通知=0

这种逻辑解决了以下问题: 1) 当用户位于地图的目标距离/半径(50m)时,仅通知用户一次 2) 如果用户离开目标半径,当他进入半径时,他将再次收到一次通知

希望这有帮助

if (distance < 50 and **notified==0**) {    
            **notified=1;** // tells your app that the user has been notified already, and wont alert again
            alert("target arrived");

        }