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下才行

  • 相关阅读:
    flume未解之谜
    flume source,sinks类型官方翻译
    flume-event类
    flume课件(连)
    source监控端口,telnet写入此端口。sinks指定目录,文件以默认时间滚动生成
    linux命令拾遗
    nginx内置变量
    nginx.conf
    hive事物开启
    hiveHA
  • 原文地址:https://www.cnblogs.com/amiezhang/p/7874503.html
Copyright © 2011-2022 走看看