`

html5 geolocation

阅读更多
使用HTML5 Geolocation构建应用
一个重要的计算距离的公式,Haversine公式:
 
Javascript实现的haversine公式代码  收藏代码
  1. Number.prototype.toRadians = function() {  
  2.     return this * Matn.PI / 180;  
  3. }  
  4.   
  5. function distance(latitude1, longitude1, latitude2, longitude2) {  
  6.     var R = 6371;  
  7.     var deltaLatitude = (latitude2 - latitude1).toRadians();  
  8.     var deltaLongitude = (longitude2 - longitude1).toRadians();  
  9.     latitude1 = latitude1.toRadians();  
  10.     latitude2 = latitude2.toRadians();  
  11.   
  12.     var a = Math.sin(deltaLatitude/2) * Math.sin(deltaLatitude/2) +  
  13.                 Math.cos(latitude1) * Math.cos(latitude2) *  
  14.                 Math.sin(deltaLongitude/2) * Math.sin(deltaLongitude/2);  
  15.     var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));  
  16.     var d = R * c;  
  17.     return d;  
  18. }  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics