zoukankan      html  css  js  c++  java
  • H5新特性之geolocation

    geolocation是H5新增的对象,它用于定位,继承在navigator对象内,以前用navigator只用到userAgent,现在就多了这个geolocation

    有2种方法(getCurrentPosition、watchPostion),4个配置属性(enableHighAccuracy,timeout,maximumAge,frequency)

    getCurrentPosition:

     1 //获取定位(一次)
     2 navigator.geolocation.getCurrentPosition(
     3     data=>{
     4         // 信息都包含在data.coords里面
     5     },
     6     err=>{
     7         // err是形如 {code: 3, message: "Timeout expired"} 的对象
     8     },
     9     {
    10         enableHighAccuracy:true, //高精度
    11         timeout: 5000,  //超时时间
    12         maximumAge: 10000 //位置缓存时间
    13     }
    14 )

    data.coords的属性:

    • coords.latitude 纬度
    • coords.longitude 经度
    • coords.altitude 海拔
    • coords.speed 速度
    • coords.accuracy 经纬度精度
    • coords.altitudeAccuracy 海拔精度
    • coords.heading 方向,从正北开始以度计

    watchPostion:

     //获取定位(一次)
     navigator.geolocation.watchPosition(
         data=>{
             // 信息都包含在data.coords里面
         },
         err=>{
             // err是形如 {code: 3, message: "Timeout expired"} 的对象
         },
         {
             enableHighAccuracy:true, //高精度
             timeout: 5000,  //超时时间
             maximumAge: 10000, //位置缓存时间
             frequency: 1000 //多久监测一次
         }
     )

    ps:geolocation已经不能在http下使用了,只能在https下才行

  • 相关阅读:
    旅行计划(拓扑排序)
    Extended traffic
    Tram(最短路)
    Cow and Friend(贪心)
    Invitation Cards(SPFA + 反向建边)
    Johnny and Another Rating Drop(找规律)
    python连接服务器上传文件,后台执行命令
    linux杀死某个进程
    linux安装杀毒软件
    django项目同一用户不能同时登陆
  • 原文地址:https://www.cnblogs.com/amiezhang/p/7874503.html
Copyright © 2011-2022 走看看