SORU
10 Mart 2011, PERŞEMBE


() toRad Javascript fonksiyonu hata atma

İki nokta için enlem ve boylamlar () tekniği How do I calculate distance between two latitude-longitude points? de açıklanan kullanma arasındaki mesafe bulmaya çalışıyorum

Kodları aşağıdaki gibidir 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

Ama uygulamaya çalıştığınızda, bir hata Uncaught TypeError: Object 20 has no Method 'toRad' söylüyor.

Özel bir kütüphane ya da almak için bir şeyler yapmam gerekir .() toRad çalışıyor mu? gibi görünüyor çünkü ikinci hat berbat.

CEVAP
10 Mart 2011, PERŞEMBE


Bir işlev bildirimi eksik.

toRad() * *7 ilk tanımlanmalıdır

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

tüm bottom of the page kod segmente göre

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • efaustus9

    efaustus9

    16 HAZİRAN 2006
  • jonathepianist

    jonathepiani

    31 Temmuz 2008
  • Photoshop Training Channel

    Photoshop Tr

    13 Temmuz 2012