PhoneGap_API_中文说明_Geolocation(地理位置).doc_第1页
PhoneGap_API_中文说明_Geolocation(地理位置).doc_第2页
PhoneGap_API_中文说明_Geolocation(地理位置).doc_第3页
PhoneGap_API_中文说明_Geolocation(地理位置).doc_第4页
PhoneGap_API_中文说明_Geolocation(地理位置).doc_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Geolocation(地理位置)在地理位置对象提供存取装置的GPS传感器。地理定位位置信息提供和经度纬度的设备,如。对位置信息的常见来源包括全球定位系统(GPS)和蓝牙地址的MAC位置,推断出网络信号,如IP地址,射频识别,无线网络和GSM / CDMA的电池识别码。不能保证给出的API返回设备的实际位置。这个API是基于W3C的地理定位API规范。有些设备已经提供了一个规范的执行情况这一点。对于这些设备,内置的支持而不是取代用于执行它与PhoneGap的。对于设备不具有地理定位的支持,PhoneGap的实施应符合W3C规范兼容。方法 geolocation.getCurrentPosition geolocation.watchPosition geolocation.clearWatch参数 geolocationSuccess geolocationError geolocationOptions对象(只读) Position PositionError Coordinatesgeolocation.getCurrentPosition返回设备作为当前的位置定位对象。navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, geolocationOptions);参数 geolocationSuccess:回调的位置,目前被调用的。 geolocationError:(可选)错误回调,就是所谓如果有一个。 geolocationOptions:(可选)地理定位选项。说明功能geolocation.getCurrentPositon是一个异步功能。它返回设备的当前位置到geolocationSuccess回调与位置参数对象的。如果有错误,geolocationError回调调用了PositionError对象。支持的平台 机器人 黑莓(操作系统4.6) 黑莓WebWorks(操作系统5.0和更高版本) iPhone简单的例子/ onSuccess Callback/ This method accepts a Position object, which contains/ the current GPS coordinates/var onSuccess = function(position) alert(Latitude: + position.coords.latitude + n + Longitude: + position.coords.longitude + n + Altitude: + position.coords.altitude + n + Accuracy: + position.coords.accuracy + n + Altitude Accuracy: + position.coords.altitudeAccuracy + n + Heading: + position.coords.heading + n + Speed: + position.coords.speed + n + Timestamp: + new Date(position.timestamp) + n);/ onError Callback receives a PositionError object/function onError(error) alert(code: + error.code + n + message: + error.message + n);navigator.geolocation.getCurrentPosition(onSuccess, onError);完整的例子 Device Properties Example / Wait for PhoneGap to load / function onLoad() document.addEventListener(deviceready, onDeviceReady, false); / PhoneGap is ready / function onDeviceReady() navigator.geolocation.getCurrentPosition(onSuccess, onError); / onSuccess Geolocation / function onSuccess(position) var element = document.getElementById(geolocation); element.innerHTML = Latitude: + position.coords.latitude + + Longitude: + position.coords.longitude + + Altitude: + position.coords.altitude + + Accuracy: + position.coords.accuracy + + Altitude Accuracy: + position.coords.altitudeAccuracy + + Heading: + position.coords.heading + + Speed: + position.coords.speed + + Timestamp: + new Date(position.timestamp) + ; / onError Callback receives a PositionError object / function onError(error) alert(code: + error.code + n + message: + error.message + n); Finding geolocation. geolocation.watchPosition手表到设备的当前位置的变化。var watchId = navigator.geolocation.watchPosition(geolocationSuccess, geolocationError, geolocationOptions);参数 geolocationSuccess:回调的位置,目前被调用的。 geolocationError:(可选)错误回调,就是所谓如果有一个。 geolocationOptions:(可选)地理定位选项。返回 弦乐:返回位置间隔一看标识,它引用的表。这款手表ID可用于geolocation.clearWatch到停止位置看,在改变。说明功能geolocation.watchPosition是一个异步功能。它返回设备的当前位置时,位置变化已被侦破。当装置检索的新的位置,geolocationSuccess调用一个回调位置参数对象的。如果有错误,geolocationError回调调用了PositionError对象。支持的平台 机器人 黑莓(操作系统4.6) 黑莓WebWorks(操作系统5.0和更高版本) iPhone简单的例子/ onSuccess Callback/ This method accepts a Position object, which contains/ the current GPS coordinates/function onSuccess(position) var element = document.getElementById(geolocation); element.innerHTML = Latitude: + position.coords.latitude + + Longitude: + position.coords.longitude + + + element.innerHTML;/ onError Callback receives a PositionError object/function onError(error) alert(code: + error.code + n + message: + error.message + n);/ Options: retrieve the location every 3 seconds/var watchID = navigator.geolocation.watchPosition(onSuccess, onError, frequency: 3000 );完整的例子 Device Properties Example / Wait for PhoneGap to load / function onLoad() document.addEventListener(deviceready, onDeviceReady, false); var watchID = null; / PhoneGap is ready / function onDeviceReady() / Update every 3 seconds var options = frequency: 3000 ; watchID = navigator.geolocation.watchPosition(onSuccess, onError, options); / onSuccess Geolocation / function onSuccess(position) var element = document.getElementById(geolocation); element.innerHTML = Latitude: + position.coords.latitude + + Longitude: + position.coords.longitude + + + element.innerHTML; / onError Callback receives a PositionError object / function onError(error) alert(code: + error.code + n + message: + error.message + n); Watching geolocation. geolocation.clearWatch停止看,变更设备的按位置引用watchID参数。navigator.geolocation.clearWatch(watchID);参数 watchID:本该ID的watchPosition间隔清楚。(字符串)说明功能geolocation.clearWatch停止看设备的位置,清除更改geolocation.watchPosition所引用的watchID。支持的平台 机器人 黑莓(操作系统4.6) 黑莓WebWorks(操作系统5.0和更高版本) iPhone简单的例子/ Options: retrieve the location every 3 seconds/var watchID = navigator.geolocation.watchPosition(onSuccess, onError, frequency: 3000 );/ .later on.navigator.geolocation.clearWatch(watchID);完整的例子 Device Properties Example / Wait for PhoneGap to load / function onLoad() document.addEventListener(deviceready, onDeviceReady, false); var watchID = null; / PhoneGap is ready / function onDeviceReady() / Update every 3 seconds var options = frequency: 3000 ; watchID = navigator.geolocation.watchPosition(onSuccess, onError, options); / onSuccess Geolocation / function onSuccess(position) var element = document.getElementById(geolocation); element.innerHTML = Latitude: + position.coords.latitude + + Longitude: + position.coords.longitude + + + element.innerHTML; / clear the watch that was started earlier / function clearWatch() if (watchID != null) navigator.geolocation.clearWatch(watchID); watchID = null; / onError Callback receives a PositionError object / function onError(error) alert(code: + error.code + n + message: + error.message + n); Watching geolocation. Clear Watch 坐标一组属性,描述的地理坐标的位置。属性 纬度:北纬以十进制度。(数目) 经度:经度十进制度。(数目) 高度:身高米以上的椭球的位置英寸(数目) 精度:精度经度和纬度水平坐标米。(号码) altitudeAccuracy:精度高度水平的坐标米。(号码) 标题:旅行,在指定的计数度顺时针相对于真北。方向(数目) 速度:设备,地面速度的规定。电流在每米每秒(号码)说明该坐标对象创建和PhoneGap居住着,并连接到位置的对象。该位置的对象,然后返回给用户通过一个回调函数。支持的平台 机器人 黑莓(操作系统4.6) 黑莓WebWorks(操作系统5.0和更高版本) iPhone简单的例子/ onSuccess Callback/var onSuccess = function(position) alert(Latitude: + position.coords.latitude + n + Longitude: + position.coords.longitude + n + Altitude: + position.coords.altitude + n + Accuracy: + position.coords.accuracy + n + Altitude Accuracy: + position.coords.altitudeAccuracy + n + Heading: + position.coords.heading + n + Speed: + position.coords.speed + n + Timestamp: + new Date(position.timestamp) + n);/ onError Callback/var onError = function() alert(onError!);navigator.geolocation.getCurrentPosition(onSuccess, onError);完整的例子 Geolocation Position Example / Set an event to wait for PhoneGap to load / function onLoad() document.addEventListener(deviceready, onDeviceReady, false); / PhoneGap is loaded and Ready / function onDeviceReady() navigator.geolocation.getCurrentPosition(onSuccess, onError); / Display Position properties from the geolocation / function onSuccess(position) var div = document.getElementById(myDiv); div.innerHTML = Latitude: + position.coords.latitude + + Longitude: + position.coords.longitude + + Altitude: + position.coords.altitude + + Accuracy: + position.coords.accuracy + + Altitude Accuracy: + position.coords.altitudeAccuracy + + Heading: + position.coords.heading + + Speed: + position.coords.speed + ; / Show an alert if there is a problem getting the geolocation / function onError() alert(onError!); Android的怪癖altitudeAccuracy:此属性不支持Android设备,它总是返回null。位置包含的位置坐标是API创建的地理位置。属性 坐标:坐标的地理设置。(坐标) 时间戳:创作时间戳坐标以毫秒为单位。(DOMTimeStamp)说明该职位的目的是通过创建和PhoneGap填充,并返回一个回调函数给用户通过。支持的平台 机器人 黑莓(操作系统4.6) 黑莓WebWorks(操作系统5.0和更高版本) iPhone简单的例子/ onSuccess Callback/var onSuccess = function(position) alert(Latitude: + position.coords.latitude + n + Longitude: + position.coords.longitude + n + Altitude: + position.coords.altitude + n + Accuracy: + position.coords.accuracy + n + Altitude Accuracy: + position.coords.altitudeAccuracy + n + Heading: + position.coords.heading + n + Speed: + position.coords.speed + n + Timestamp: + new Date(position.timestamp) + n);/ onError Callback receives a PositionError object/function onError(error) alert(code: + error.code + n + message: + error.message + n);navigator.geolocation.getCurrentPosition(onSuccess, onError);完整的例子 Device Properties Example / Wait for PhoneGap to load / function onLoad() document.addEventListener(deviceready, onDeviceReady, false); / PhoneGap is ready / function onDeviceReady() navigator.geolocation.getCurrentPosition(onSuccess, onError); / onSuccess Geolocation / function onSuccess(position) var element = document.getElementById(geolocation); element.innerHTML = Latitude: + position.coords.latitude + + Longitude: + position.coords.longitude + + Altitude: + position.coords.altitude + + Accuracy: + position.coords.accuracy + + Altitude Accuracy: + position.coords.altitudeAccuracy + + Heading: + position.coords.heading + + Speed: + position.coords.speed + + Timestamp: + new Date(position.timestamp) + ; / onError Callback receives a PositionError object / function onError(error) alert(code: + error.code + n + message: + error.message + n); Finding geolocation. iPhone怪癖 时间戳:使用毫秒秒而不是。一种解决方法是手动转换时间戳毫秒( 1000): var onSuccess = function(position) alert(Latitude: + position.coords.latitude + n + Longitude: + position.coords.longitude + n + Timestamp: + new Date(position.timestamp * 1000) + n); ;PositionError一个PositionError对象被返回到geolocationError回调时发生错误。属性 代码:下面一个预定义列出的错误代码。 消息:错误消息,描述错误的详细信息的困难。常数 PositionError 。PERMISSION_DENIED PositionError 。POSITION_UNAVAILABLE PositionError 。超时说明该PositionError对象被返回到用户通过geolocationError回调函数发生错误时的地理位置。geol

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论