|
|
1
0
Html5 getcurrentposition函数异步工作,因此所有处理都在getcurrentposition函数中进行。 var locationsOfInterest=[];var currentlat=0;var currentlong=0;x=导航器。地理位置;x、 getCurrentPosition(getposition);函数getposition(position){currentlat=position.coords.latitude;currentlong=position.coords.latitude; var sunwayuni={title:“Sunway大学”,纬度:3.0681,经度:101.6041,}var monashaustralia={title:“Monash Australia”,纬度:-37.876823,经度:145.045837,}var kualalumpur={title:“吉隆坡”,纬度:3.1390,经度:101.6869,}locationsOfInterest=[sunwayuni,monashaustralia,kualalumpur]for(var i=0;i<locationsOfInterest.length;i++){locationsOfInterest[i]。距离=calcCrow(locationsOfInterest[i]。纬度,locationsOfInterest[i]。经度);}函数calcCrow(lat2,lon2){var R=6371;//km var drLat=toRad(lat2 currentlat);var drLon=toRad(lon2 currentlong);var rlat1=toRad(currentlat);var rlat2=toRad(lat2);var a=Math.sin(drLat/2)*Math.sin(drLat/2)+Math.sin(drLon/2)*Math.sin(drLon/2)*Math.cos(rlat1)*Math.cos(rlat2);var c=2*Math.atan2(Math.sqrt(a),Math..sqrt(1-a));var d=R*c;返回d;}//将数值度转换为弧度函数toRad(Value){返回值*Math.PI/180;} }; |