Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.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
返回“返回”;“职位”;来自getCurrentPosition的数据。Phonegap、HTML5、Javascript_Javascript_Html_Jquery Mobile_Geolocation - Fatal编程技术网

返回“返回”;“职位”;来自getCurrentPosition的数据。Phonegap、HTML5、Javascript

返回“返回”;“职位”;来自getCurrentPosition的数据。Phonegap、HTML5、Javascript,javascript,html,jquery-mobile,geolocation,Javascript,Html,Jquery Mobile,Geolocation,好的,对不起,我一直在想如何返回整个物体的位置。因此,我可以在稍后调用getCurrentPosition的函数中访问其中的项。这是我试图做的一个模拟。谢谢你的帮助 function aFunctionName(){ pos = navigator.geolocation.getCurrentPosition(onGeoSuccess, geoFail); cameraLat = pos.coords.latitude; \\cannot read proper

好的,对不起,我一直在想如何返回整个物体的位置。因此,我可以在稍后调用getCurrentPosition的函数中访问其中的项。这是我试图做的一个模拟。谢谢你的帮助

 function aFunctionName(){   
    pos = navigator.geolocation.getCurrentPosition(onGeoSuccess, geoFail);
    cameraLat = pos.coords.latitude;
     \\cannot read property coords
     console.log(cameraLat);
    cameraLong = pos.coords.longitude;
     \\cannot read property coords
     console.log(cameraLong);
    cameraTimestamp = pos.timestamp;
     console.log(cameraTimestamp)
     \\Cant read property timestamp
}

function onGeoSuccess(position) {
    cameraLati = position.coords.latitude;
     console.log(cameraLati);
     \\works fine and displays the lat
    cameraLongi = position.coords.longitude;
     console.log(cameraLongi);
     \\works fine and displays the long
    cameraTimestampi = position.timestamp;
     console.log(cameraTimestampi);
     \\works fine and displays the timestamp
   return position;
}
function onGeofail() {
  console.log("error");
}

getCurrentLocation的调用不是同步操作,因此您将无法执行正在尝试的操作。但是,您正在传递一个onGeoSuccess函数,并可能获得一个有效的位置。您能否在该功能中不执行您需要执行的操作(事实上,您正在执行)

[根据新信息更新] 好的,如果您需要在success函数中添加一些额外变量,请尝试以下操作:

function saveDataWithPosition(data1, data2, data3, etc.){
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(
            function (position) {   
                // Insert data
                // Here you'll have access to your data params
                // and the position obj
            }, function (error) {               
                // Handle the error how you wish
            }, {
                enableHighAccuracy: true
            }
        );
    }
}

我希望这会有所帮助,更重要的是,我希望它能起作用。

问题是我正在试图保存这些跳线,以便以后使用。这是我正在使用的移动应用程序,我将地理位置和照片信息存储在数据库中。问题是由于我需要强制执行的唯一键约束,insert语句是一次性完成的,我无法先执行insert,然后执行更新,因此我无法在onGeoSuccess中执行操作,因为我无法将照片信息传递给数据库。如果我遗漏了什么,请道歉,但是为什么不能从“success”函数中进行插入呢?我需要传递图像数据和“affunctionname”函数中已经存在的一系列其他信息。你认为我应该把所有的信息(大约8个变量)传递给ONGEOSUCESS函数吗?navigator.geolocation.getCurrentPosition(onGeoSuccess(var1,var2,var3,var4,var5,var6,var7,var8),geoFail)?你不能那样做。我很快会更新我的答案。这将是明智的更新您的问题,包括您刚才告诉我的细节。谢谢你,我会测试和张贴,如果它工作,只要我一回到家。