HTML5地理定位

时间:2023-03-09 15:52:13
HTML5地理定位

1.通过navigator.geolocation来获取设备当前位置,返回一个位置对象,可以获得当前经纬度相关信息;

2.navgatior.geolocation的三个方法:

  getCurrentPosition();

  watchPosition();

  clearWatch();

3.getCurrentPosition()使用方法

  navigator.geolocation.getCurrentPosition(successCallback,[errorCallback],[positionOptons]);

  A) successCallback 获取定位成功时执行的回调函数 eg: function(position){alert("纬度:"+position.coords.latitude+";经度:"+position.coords.longitude)};

successCallback返回一个地理数据对象position作为参数,该对象有属性timestamp和coords。timestamp表示该地理数据创建时间(时间戳);coords包括另外七个属性:

  1. coords.latitude:估计纬度
  2. coords.longitude:估计经度
  3. coords.altitude:估计高度
  4. coords.accuracy:所提供的以米为单位的经度和纬度估计的精确度
  5. coords.altitudeAccuracy:所提供的以米为单位的高度估计的精确度
  6. coords.heading: 宿主设备当前移动的角度方向,相对于正北方向顺时针计算

  7. coords.speed:以米每秒为单位的设备的当前对地速度