title: HTML Coordinate Distance Calculator not printing
body: <p>I've been working on this HTML/Javascript code using the Haversine formula, in order to tell the distance between two devices. It's not currently finished however the code should be readable. For some reason "d" the final variable for the distance isn't printing (document.write) after calculation. The site is currently hosted at <a href="http://magebattle.netau.net/" rel="nofollow">http://magebattle.netau.net/</a> however in order to make this post clean please view the source code on there, instead of me putting it all here. (Sorry about indentation)
  Relevant JS:</p>
  
  <pre><code>            // Wait for device API libraries to load
              //
              document.addEventListener("deviceready", onDeviceReady, false);
              // device APIs are available
              //
              function onDeviceReady() {
                  navigator.geolocation.getCurrentPosition(onSuccess, onError);
              }
              // onSuccess Geolocation
              //
              function onSuccess(position) {
                  var lat2 = position.coords.latitude             
                              var lon2 = position.coords.longitude
                              var lat1 = 42.806911; 
              var lon1 = -71.290611; 
              var R = 6371; // km 
              //has a problem with the .toRad() method below.
              var x1 = lat2-lat1;
              var dLat = x1.toRad();  
              var x2 = lon2-lon1;
              var dLon = x2.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; 
              document.write(d);
              }
  
              // onError Callback receives a PositionError object
              //
              function onError(error) {
                  alert('code: '    + error.code    + '\n' +
                      'message: ' + error.message + '\n');
              }
          Number.prototype.toRad = function() {
                      return this * Math.PI / 180;
          }           
  </code></pre>