JavaScript将坐标从一个函数传递到另一个函数

JavaScript将坐标从一个函数传递到另一个函数,javascript,function,variables,Javascript,Function,Variables,我在将两个坐标从一个函数传递到另一个函数时遇到问题。我不太懂JavaScript,但它似乎有点正确。你能告诉我我的错误在哪里吗 <head> <script> var zoom = 12; // 18 for mobile phones because the geolocation is more accurate function init() { // Don't bother if the w

我在将两个坐标从一个函数传递到另一个函数时遇到问题。我不太懂JavaScript,但它似乎有点正确。你能告诉我我的错误在哪里吗

     <head>
      <script>
       var zoom = 12; // 18 for mobile phones because the geolocation is more accurate 

       function init() {
         // Don't bother if the web browser doesn't support cross-document messaging
         if (window.postMessage) {
           if (navigator && navigator.geolocation) {
             try {
               navigator.geolocation.getCurrentPosition(function(pPos) {
               send(pPos.coords.latitude, pPos.coords.longitude);
             }, function() {});
             } catch (e) {}
           } else if (google && google.gears) {
             // Relevant if targeting mobile phones (some of which may have Google Gears)
             try {
               var geoloc = google.gears.factory.create("beta.geolocation");
               geoloc.getCurrentPosition(function(pPos) {
               send(pPos.latitude, pPos.longitude);
             }, function() {});
             } catch (e) {}
           }
         }
       }

       function send(pLat, pLng) {
         var myiframe = document.getElementById("myiframe").contentWindow;
         // The third parameter, zoom, is optional
         myiframe.postMessage(pLat + "," + pLng + "," + zoom, "http://www.qib.la");
       }

       window.onload=init;
      </script>
     </head>

     <body>
      <iframe id="myiframe" src="http://www.qib.la/embed/" width="400" height="400">
        Check the prayer direction towards the Ka'ba in Makkah at
        <a href="http://www.qib.la/">Qibla Direction</a>.
      </iframe>

<script type="text/javascript" src="http://praytimes.org/code/v2/js/PrayTimes.js"></script>

<br>
<p align="center">Waterloo, ON, Canada<p>
<div align="center" id="table"></div>

<script type="text/javascript">

    var date = new Date(); // today
    var times = prayTimes.getTimes(date, pLat + "," + pLng, -5);
    var list = ['Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Maghrib', 'Isha', 'Midnight'];

    var html = '<table id="timetable">';
    html += '<tr><th colspan="2">'+ date.toLocaleDateString()+ '</th></tr>';
    for(var i in list)  {
        html += '<tr><td>'+ list[i]+ '</td>';
        html += '<td>'+ times[list[i].toLowerCase()]+ '</td></tr>';
    }
    html += '</table>';
    document.getElementById('table').innerHTML = html;

</script>


     </body>

var zoom=12;//18,因为地理位置更准确
函数init(){
//如果web浏览器不支持跨文档消息传递,就不用麻烦了
if(window.postMessage){
if(navigator&&navigator.geolocation){
试一试{
navigator.geolocation.getCurrentPosition(函数(pPos){
发送(pPos.coords.latitude,pPos.coords.latitude);
},函数(){});
}捕获(e){}
}else if(google&&google.gears){
//如果目标是移动电话(其中一些可能有谷歌Gears),则相关
试一试{
var geoloc=google.gears.factory.create(“beta.geolocation”);
geoloc.getCurrentPosition(功能(pPos){
发送(纬度,经度);
},函数(){});
}捕获(e){}
}
}
}
功能发送(平台、pLng){
var myiframe=document.getElementById(“myiframe”).contentWindow;
//第三个参数zoom是可选的
myiframe.postMessage(平台+”,“+pLng+”,“+zoom,”http://www.qib.la");
}
window.onload=init;
查看麦加的卡巴祈祷方向
.

加拿大安大略州滑铁卢

变量日期=新日期();//今天


var times=prayTimes.getTimes(日期,pLat+,“+pLng,-5); 变量列表=['Fajr'、'Sunrise'、'Dhuhr'、'Asr'、'Maghrib'、'Isha'、'Midnight']; var html=''; html++''+日期。toLocaleDateString()+''; 用于(列表中的var i){ html+=''+列表[i]+''; html+=''+次[list[i].toLowerCase()]+''; } html+=''; document.getElementById('table')。innerHTML=html;

是否可以从异步函数返回值?如何在此处使用回调?

此代码中存在语法错误:

var times = prayTimes.getTimes(date, + b + ',' + c + , -5);
你有一个“+”和一个逗号紧跟其后。我不确定您对代码的意图是什么,但这正是导致代码无法运行的原因

也许您打算遵循将逗号作为字符串附加的模式

var times = prayTimes.getTimes(date + ',' + b + ',' + c + ',' + -5);
或者-5是一个单独的论点

var times = prayTimes.getTimes(date, b + ',' + c, -5);

你有什么问题?错误是什么?我试图在这里获得纬度和经度var times=prayTimes.getTimes(date,+b+,“+c+,-5);像这样的var times=prayTimes.getTimes(date,+lat+,'+long+,-5);var times=prayTimes.getTimes(日期,pLat+,“+pLng,-5);编辑了整个代码,我只是不知道怎么做。不确定你的意思,你能试着澄清一下吗?我试图将纬度和经度传递给这个变量var times=prayTimes.getTimes(date,[42.19,-70.72],-5);其中42.19,-70.72是使用谷歌地理定位功能获得的纬度和经度值。