无意中看到了介绍firefox的geolocation API的文章,原文链接如下:
Using geolocation
https://developer.mozilla.org/en/Using_geolocation
1. The geolocation object
GEO服务由对象geolocation提供, 它是navigator下的一个子对象。如下代码可检测browser是否支持geolocation。
if (navigator.geolocation) {
/* geolocation is available */
} else {
alert("I'm sorry, but geolocation services are not supported by your browser.");
}
而在firefox addon中则需用另一种方式:
var geolocation = Components.classes["@mozilla.org/geolocation;1"]
.getService(Components.interfaces.nsIDOMGeoGeolocation);
2. Getting the current position
使用对象方法getCurrentPosition(), 它发送一个异步请求或用position hardware来获得位置信息,当有结果被返回时将调用一个回调函数。getCurrentPosition需传一个回调函数,一个可选 的错误回调,和一个可选 的参数对象。
navigator.geolocation.getCurrentPosition(function(position) {
do_something(position.coords.latitude, position.coords.longitude);
});
3. Watching the current position
使用getCurrentPosition()。当位置数据改变时,同样会调用回调函数。需要的参数和getCurrentPosition()相同。
clearWatch()用于停止监视位置信息。
var watchID = navigator.geolocation.watchPosition(function(position) {
do_something(position.coords.latitude, position.coords.longitude);
});
navigator.geolocation.clearWatch(watchID);
var wpid = navigator.geolocation.watchPosition(geo_success, geo_error, {enableHighAccuracy:true, maximumAge:30000, timeout:27000});
一个示例网站:
http://www.thedotproduct.org/experiments/geo/
分享到:
相关推荐
地理定位 使用 PHP 实现的 Google Geolocation API。
html开发
您需要具有访问Google Maps Geolocation API的Google API密钥。 例子 const geolocation = require ( 'google-geolocation' ) ( { key : 'api key' } ) ; // Configure API parameters const params = { ...
Geolocation是HTML5标准下的一个Web API,利用它可以获取设备的当前位置信息(坐标),本篇文章主要介绍了三个方法,非常具有实用价值,需要的朋友可以参考下
HTML5的地理定位功能演示
Angular的地理位置API 部分 这是与Angular一起使用的基于基于Observable的抽象安装如果您没有 : npm i @ng-web-apis/common现在安装软件包: npm i @ng-web-apis/geolocation如何使用GeolocationService ...
安装使用npm : npm install --save react-hook-geolocation 使用yarn : yarn add react-hook-geolocation用法 import React from 'react'import useGeolocation from 'react-hook-geolocation'const ...
Geolocation API扩展了。 当前,在Android上,它使用 。 Google不推荐使用此API,因为它不如推荐的准确和慢。 这是我们希望在不久的将来更改的内容 。 为了将新的与React Native一起使用,请查看替代库: 入门 ...
前端项目-jQuery-Geolocation,jQuery plugin which acts as a simplification of the W3C Geolocation API
GeoLocation API的承诺包装 用法 GeoPromise同时具有静态和原型方法。 静态介面 getCurrentPosition #####参数 选项:可选的<Object> 。 使用 #####返回 #####句法 GeoPromise . ...
MockGeolocation 是一个用于模拟 html 5 geolocation api 的库。 用法 // simulate a geolocation MockGeolocation.setCurrentLatLng(53.4152431, -8.2390307) // get current position navigator.geolocation....
在手持设备如此普遍的今天,位置信息对于应用程序来讲是极其重要...基本用法 首先,我们可以从浏览器的navigator对象中通过geolocation属性获取到一个Geolocation的实例,如下图所示: 图中我们可以看到,Geolocation
PhoneGap,API帮助文档翻译整理9-Geolocation_(定位)
一个基于Geolocation API,AmbientLightSensor API和WakeLock API的小巧,简洁的速度计渐进式Web应用程序。 为什么? 因为我的2005 Prius上的组合仪表处于故障状态,所以我需要一个测速仪,直到可以拆开并修理有...
Api-il-ilce-mahalle-geolocation-rest-api.zip,蒂尔基耶伊桑,伊尔塞姆特维拉班。Bélgesel Bilgiler_l,_l_e,Bélge ve Mahalle Bilgisi_in rest-API,一个api可以被认为是多个软件设备之间通信的指导手册。例如,...
这个项目是我的一次面试任务的一部分要求如下使用浏览器 Geolocation API,查找当前用户位置并查询 google place API 以获取附近的餐馆列表。 设计要求清单包括: 带有交互式图钉的地图视图,悬停时会显示有关所选...
这部分共6章,介绍了Geolocation API在浏览器代码中的使用,并通过大量示例向读者展示其“一次编写,随处部署”的特点。具体内容包括地理定位的基础知识简介,这套API的浏览器支持情况,以及如何利用它和其他常用...
ng地理定位器 让用户借助 HTML5 Geolocation API 和 Google Maps 告诉您他们在哪里。 现场演示: : 该项目使用作为起点。安装 npm install --save ng-geolocator或者 bower install --save ng-geolocator入门有关...
挑战使您可以提高现实工作流程中的技能。 为了应对这一挑战,您需要对HTML,CSS和JavaScript有基本的了解。挑战您面临的挑战是构建此IP地址跟踪器应用程序,并使它看起来与设计尽可能接近。 要获取IP地址位置,您将...