`
leonzhx
  • 浏览: 793742 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

You Are Here (And So Is Everybody Else)

 
阅读更多

1.   Geolocation is the art of figuring out where you are in the world and (optionally) sharing that information with people you trust. There is more than one way to figure out where you are — your IP address, your wireless network connection, which cell tower your phone is talking to, or dedicated GPS hardware that calculates latitude and longitude from information sent by satellites in the sky.

 

 

2.   User Agents must not send location information to Web sites without the express permission of the user.

 

3.   The simplest use of the geolocation API looks like this:

function get_location() {

  navigator.geolocation.getCurrentPosition(show_map);

}
 

The call to getCurrentPosition() will return immediately, but that doesn’t mean that you have access to the user’s location. The first time you are guaranteed to have location information is in the callback function. The callback function looks like this:

 

 

function show_map(position) {

  var latitude = position.coords.latitude;

  var longitude = position.coords.longitude;

  // let's show a map or do something interesting!

} 

 

 

4.   The callback function will be called with a single parameter, an object with two properties: coords and timestamp . The timestamp is just that, the date and time when the location was calculated. The coords object has properties like latitude and longitude which are exactly what they sound like: the user’s physical location in the world.


 Only three of the properties are guaranteed to be there (coords.latitude , coords.longitude , and coords.accuracy ). The rest might come back null , depending on the capabilities of your device and the backend positioning server that it talks to. The heading and speed properties are calculated based on the user’s previous position, if possible.

 

5.   You can pass a second argument to the getCurrentPosition() function which is an error handling callback function. If anything goes wrong, your error callback function will be called with a PositionError object which has a code and message property. The code property will be one of :

  a)   PERMISSION_DENIED (1) if the user denies your access to their location.

  b)   POSITION_UNAVAILABLE (2) if the network is down or the positioning satellites can’t be contacted.

  c)   TIMEOUT (3) if the network is up but it takes too long to calculate the user’s position.

 

6.   The getCurrentPosition() function has an optional third argument, a PositionOptions object . There are three properties you can set in a PositionOptions object: enableHighAccuracy , timeout and maximumAge . All the properties are optional. You can set any or all or none of them. The timer doesn’t start counting down until after the user gives permission to even try to calculate their position. You’re not timing the user; you’re timing the network. The maximumAge property allows the device to answer immediately with a cached position calculated whthin maximumAge milliseconds before.

 

7.   The watchPosition() function has the same structure as getCurrentPosition() . It takes two callback functions, a required one for success and an optional one for error conditions, and it can also take an optional PositionOptions object that has all the same properties. The difference is that your callback function will be called every time the user’s location changes. The watchPosition() function itself returns a number. You should probably store this number somewhere. If you ever want to stop watching the user’s location change, you can call the clearWatch() method and pass it this number, and the device will stop calling your callback function.

 

8.   Gears is an open source browser plugin from Google. It provides features for older browsers. One of the features that Gears provides is a geolocation API . It’s not quite the same as the W3C geolocation API , but it serves the same purpose.

 

9.   geo.js is an open source, MIT -licensed JavaScript library that smooths over the differences between the W3C geolocation API , the Gears API , and the API s provided by mobile platforms. To use it, you’ll need to add two <script> elements at the bottom of your page:

 

<script src="gears_init.js"></script>

<script src="geo.js"></script> 
 

First, you need to explicitly call an init() function. The init() function returns true if a supported geolocation API is available. To actually find your location, you need to call the getCurrentPosition() function:

if (geo_position_js.init()) {

  geo_position_js.getCurrentPosition(geo_success, geo_error);

}
 

geo.js does not currently support the watchPosition() function.

 

  • 大小: 24.9 KB
分享到:
评论

相关推荐

    MATLAB.rar_You Are Here

    标题 "MATLAB.rar_You Are Here" 暗示了这是一个包含MATLAB相关代码和资源的压缩包。MATLAB(Matrix Laboratory)是一款广泛应用于工程计算、数据分析、算法开发和系统建模的高级编程环境。本压缩包可能包含了多个...

    Optical Lithography: Here is Why

    This book is aimed at new and experienced engineers, technology managers, and senior technicians who want to enrich their understanding of the image formation physics of a lithographic system....

    You Are Here-crx插件

    【You Are Here-crx插件】是一款专为英文用户设计的浏览器扩展程序,它主要针对美国用户群体。这款插件的核心功能是帮助用户更好地管理和跟踪他们在网络上的浏览历史和当前活动,让用户的在线体验更加个性化和高效。...

    Where are you I am here..doc

    I am here.":老师通过角色扮演来演示这个句型,引导孩子们一起说"Mrs Zhao, where are you? I am here.",然后邀请个别孩子尝试回答。 3. 三人游戏:进一步增加难度,让三个孩子参与游戏,大家轮流问"Where are ...

    Power Query for Power BI and Excel

    Query is here to free you from these dull, repetitive tasks and give you time to concentrate on what’s important: analyzing your data and gaining insights from it. Even better, Power Query is easy to...

    第6版Programming.Windows writing Windows 8 apps with XAML and C#

    What you are reading right now is a preview ebook version of the book. This preview version is based on the Consumer Preview of Windows 8, which was released on February 29, 2012. Microsoft has ...

    外研版一起小学英语三下册《Module 6Unit 1 Here are his hands.》word教案.docx

    同时,教学重点是让学生学会使用存在和数量的句型:“Here is…”和“There is/There are…”。 在教学过程中,教师首先通过唱英文歌曲"Head and Shoulders"来预热课堂,复习身体部位的单词,强调单数形式的发音。...

    A-Practical-Guide-to-LATEX-Tips.pdf

    But that is often the moment where you lack of time and that you are happy to find complete solutions. That is a moment where you tell to yourself “Is there no folk out there to give me such a ...

    unity蛇大战方块游戏源码

    The goal here is to collect as much food as you can to make your snake grow, while you are exploding the blocks toat are blocking your way. Each time you hit a block, you lose a part of your snake. ...

    thisis和hereis的区别.doc

    2. **引起注意**:当某个事物出现或者到达时,可以使用 "Here is/are" 来吸引他人的注意力。例如:"Here comes the bus, let's hurry up."(公交车来了,我们快点。) 值得注意的是,"Here is" 后面通常跟名词或者...

    Black Hat PytHon Python Programming for Hackers and Pentesters

    I want to give you the bare minimum, with a little flavor, so that you have some foundational knowl- edge. With that in mind, I’ve sprinkled ideas and homework assignments throughout the book to ...

    BMDThread v1.8

    Well here it is, the TBMThread is a native VCL component implementing everything you do need to create the thread and the synchronization, just dropping the component on the form. Sounds great, right...

    幼儿园教案2021-Where are you I am here..doc

    I am here.",旨在教授幼儿理解和学习英语句型“Where are you?”和“I am here.”。教案结合了“我眼里的秋天”这一主题,通过游戏的方式,让孩子们在轻松愉快的环境中学习和巩固英语知识。 首先,教案的设计背景...

    VC控制字体源码下载

    // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef...

    Programming Embedded Systems in C and C++

    nonsense style of this book will help you get started by offering practical advice from someone who's been in your shoes and wants to help you learn quickly &lt;br&gt;The techniques and code examples ...

    DDKWizard 安装包及ddkbuild_cmd,ddkbuild_bat(用于DDK开发环境搭建)

    Of course the template files are predefined and so is the content of the project(s) within certain limits. However, I tried to choose the best options that I could think of and provide a way to ...

Global site tag (gtag.js) - Google Analytics