Xav*_*vio 3 javascript html5 gps geolocation
正如标题所示.知道怎么做到这一点?
一直在查看http://www.html5archive.com/2010/12/04/geolocation-api-example-distance-tracking/并试图修改该代码,但没有运气.
它最初不需要自动刷新.
但基本功能应该获得用户位置并告知用户和特定点之间的距离.
密钥代码在此页面上,与您指定的密钥相关联.我把它转换成下面的函数:
/** Extend Number object with method to convert numeric degrees to radians */
if (typeof Number.prototype.toRadians == 'undefined') {
Number.prototype.toRadians = function() { return this * Math.PI / 180; };
}
function getDistance(lat1,lon1,lat2,lon2) {
var R = 6371; // km
var dLat = (lat2-lat1).toRadians();
var dLon = (lon2-lon1).toRadians();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(lat1.toRadians()) * Math.cos(lat2.toRadians()) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return R * c;
}
Run Code Online (Sandbox Code Playgroud)
你需要将特定的lat和lon作为前两个参数传递给它,将当前的lat和lon作为第二个参数传递给它.
| 归档时间: |
|
| 查看次数: |
3789 次 |
| 最近记录: |