Link to home
Start Free TrialLog in
Avatar of Wajdi Methlouthi
Wajdi Methlouthi

asked on

nan value

im getting NaN result !!


distance(lat1, lon1, lat2, lon2) {
  this.R =  6371; // RadparseIntius of the earth in km
  this.dLat = this.deg2rad(lat2 - lat1); // deg2rad below
  this.dLon = this.deg2rad(lon2 - lon1);
    var a =
      Math.sin(this.dLat / 2) * Math.sin(this.dLat / 2) +
      Math.cos(this.deg2rad(lat1)) * Math.cos(this.deg2rad(lat2)) *
      Math.sin(this.dLon / 2) * Math.sin(this.dLon / 2);
  
  this.c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  this.d =   this.R * this.c; // Distance in km
  
    return this.d;
  
  }

Open in new window

Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

What data are you passing to the function?
How are you calling it?
What do you get with ?
could you give the values you get in the alert?
distance(lat1, lon1, lat2, lon2) {
     alert(lat1 + " / " + lon1 + " / " + lat2 + " / " + lon2 );
     return 12.34;  
  }

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.