appMobi watchPosition和getCurrentPosition失败,我的小GPS图标出现并继续,但是从appmobi网站复制和粘贴他们的确切示例,我应该至少得到一个警报,如果不是那么在控制台中出现错误我没有得到的调试器。
var options = {timeout: 10000, maximumAge: 11000, enableHighAccuracy: true };
//This function is called on every iteration of the watch Position command that fails
var fail = function(){
alert("Geolocation failed. \nPlease enable GPS in Settings.");
};
//This function is called on every iteration of the watchPosition command that is a success
var suc = function(p){
alert("Moved To: Latitude:" + p.coords.latitude + "Longitude: " + p.coords.longitude;
};
//This command starts watching the geolocation
var geolocationWatchTimer = AppMobi.geolocation.watchPosition(suc,fail,options);
//Call the stopGeolocation function to stop the geolocation watch
var stopGeolocation = function(){
AppMobi.geolocation.clearWatch(geolocationWatchTimer);
}
......
更新
好的,注意到即使在那里使用示例代码也被破坏了。缺少a)和a;所以有了这些,我现在得到Uncaught TypeError: Cannot call method 'watchPosition' of undefined
好的, 再次更新
修复了最后一个问题,但是这一个让我感到困惑,似乎它现在运行了2次才停止,我需要它才能运行一次。我怎么能得到它?
答案 0 :(得分:0)
放一个标志只运行一次。:
...lat=0;
var suc = function(p){
if ((p.coords.latitude != undefined)&&(lat==0))
{
console.log(p.coords.latitude);
lat=p.coords.latitude;
...