0

ある関数から別の関数に 2 つの座標を渡す際に問題が発生しています。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>

非同期関数から値を返すことは可能ですか? ここでコールバックを使用するにはどうすればよいですか?

4

1 に答える 1

0

このコードには構文エラーがあります:

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);
于 2013-04-20T04:49:44.460 に答える