• <i id='c6Bq0'><tr id='c6Bq0'><dt id='c6Bq0'><q id='c6Bq0'><span id='c6Bq0'><b id='c6Bq0'><form id='c6Bq0'><ins id='c6Bq0'></ins><ul id='c6Bq0'></ul><sub id='c6Bq0'></sub></form><legend id='c6Bq0'></legend><bdo id='c6Bq0'><pre id='c6Bq0'><center id='c6Bq0'></center></pre></bdo></b><th id='c6Bq0'></th></span></q></dt></tr></i><div id='c6Bq0'><tfoot id='c6Bq0'></tfoot><dl id='c6Bq0'><fieldset id='c6Bq0'></fieldset></dl></div>

    1. <legend id='c6Bq0'><style id='c6Bq0'><dir id='c6Bq0'><q id='c6Bq0'></q></dir></style></legend>

      <small id='c6Bq0'></small><noframes id='c6Bq0'>

          <bdo id='c6Bq0'></bdo><ul id='c6Bq0'></ul>

        <tfoot id='c6Bq0'></tfoot>

      1. toRad() Javascript 函数抛出错误

        时间:2023-09-06

          • <bdo id='LnHrS'></bdo><ul id='LnHrS'></ul>

              <small id='LnHrS'></small><noframes id='LnHrS'>

            • <tfoot id='LnHrS'></tfoot>
                  <i id='LnHrS'><tr id='LnHrS'><dt id='LnHrS'><q id='LnHrS'><span id='LnHrS'><b id='LnHrS'><form id='LnHrS'><ins id='LnHrS'></ins><ul id='LnHrS'></ul><sub id='LnHrS'></sub></form><legend id='LnHrS'></legend><bdo id='LnHrS'><pre id='LnHrS'><center id='LnHrS'></center></pre></bdo></b><th id='LnHrS'></th></span></q></dt></tr></i><div id='LnHrS'><tfoot id='LnHrS'></tfoot><dl id='LnHrS'><fieldset id='LnHrS'></fieldset></dl></div>

                    <tbody id='LnHrS'></tbody>
                  <legend id='LnHrS'><style id='LnHrS'><dir id='LnHrS'><q id='LnHrS'></q></dir></style></legend>
                  本文介绍了toRad() Javascript 函数抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  I'm trying to find the distance between two points (for which I've latitudes & longitudes) using the technique described here at Calculate distance between two latitude-longitude points? (Haversine formula)

                  The codes are as below Javascript:

                  var R = 6371; // Radius of the earth in km
                  var dLat = (lat2-lat1).toRad();  // Javascript functions in radians
                  var dLon = (lon2-lon1).toRad(); 
                  var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
                          Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
                          Math.sin(dLon/2) * Math.sin(dLon/2); 
                  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
                  var d = R * c; // Distance in km
                  

                  But when I try to implement it, an error shows up saying Uncaught TypeError: Object 20 has no Method 'toRad'.

                  Do I need a special library or something to get .toRad() working? because it seems to be screwing up on the second line.

                  解决方案

                  You are missing a function declaration.

                  In this case toRad() must be defined first as:

                  /** Converts numeric degrees to radians */
                  if (typeof(Number.prototype.toRad) === "undefined") {
                    Number.prototype.toRad = function() {
                      return this * Math.PI / 180;
                    }
                  }
                  

                  according to the code segment all at the bottom of the page

                  这篇关于toRad() Javascript 函数抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:getCurrentPosition() 和 watchPosition() 在不安全的来源上 下一篇:如何获得客户的准确当地时间?

                  相关文章

                  最新文章

                  <i id='xEfQX'><tr id='xEfQX'><dt id='xEfQX'><q id='xEfQX'><span id='xEfQX'><b id='xEfQX'><form id='xEfQX'><ins id='xEfQX'></ins><ul id='xEfQX'></ul><sub id='xEfQX'></sub></form><legend id='xEfQX'></legend><bdo id='xEfQX'><pre id='xEfQX'><center id='xEfQX'></center></pre></bdo></b><th id='xEfQX'></th></span></q></dt></tr></i><div id='xEfQX'><tfoot id='xEfQX'></tfoot><dl id='xEfQX'><fieldset id='xEfQX'></fieldset></dl></div>

                  <small id='xEfQX'></small><noframes id='xEfQX'>

                  <legend id='xEfQX'><style id='xEfQX'><dir id='xEfQX'><q id='xEfQX'></q></dir></style></legend>
                  1. <tfoot id='xEfQX'></tfoot>

                      • <bdo id='xEfQX'></bdo><ul id='xEfQX'></ul>