Code Monkey home page Code Monkey logo

getlocation's Introduction

getLocation

html5网页获取地理位置

HTML5 Geolocation API (地理位置应用程序接口)

目前PC浏览器支持情况:Location

Location

Firefox 3.5+ Chrome 5.0+ Safari 5.0+ Opera 10.60+ Internet Explorer 9.0+

手机支持情况:

Android 2.0+ iPhone 3.0+ Opera Mobile 10.1+ Symbian (S60 3rd & 5th generation) Blackberry OS 6 Maemo

检测浏览器是否支持

if ( navigator.geolocation ) {
    console.log("浏览器支持");
}else{
    console.log("浏览器不支持");
}

navigator.geolcation 对象下面 提供了三个方法

//获取用户当前位置
navigator.geolocation.getCurrentPosition(onSuccess,onError,option);

//监听用户位置  持续获取用户当前位置
navigator.geolocation.watchPosition(onSuccess,onError,option)

//取消监听
navigator.geolocation.clearWatch(watchID)

onSuccess , onError , option 参数说明

//onSuccess方法成功时调用的(必选),onError方法失败是调用的(可选),options其他参数(可选)

//onSuccess 的 属性值有很多 ,常用的有获取坐标的经纬度

function onSuccess(positon){

    //返回用户位置
    //经度
    var longitude = position.coords.longitude;
    //纬度
    var latitude       = position.coords.latitude;

}

options = {
     enableHighAccuracy,   //boolean 是否要求高精度的地理信息
     timeout,         //表示等待响应的最大时间,默认是0毫秒,表示无穷时间
     maximumAge        //应用程序的缓存时间
}

获取当前位置加上偏移量会准一点
经度+经度校正值: 0.008774687519;
纬度+纬度校正值: 0.00374531687912;
doc By DanceSmile

getlocation's People

Contributors

dancesmile avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.