---
title: Geolocation
description: Access GPS data.
---
|AppVeyor|Travis CI|
|:-:|:-:|
|[![Build status](https://ci.appveyor.com/api/projects/status/github/apache/cordova-plugin-geolocation?branch=master)](https://ci.appveyor.com/project/ApacheSoftwareFoundation/cordova-plugin-geolocation)|[![Build Status](https://travis-ci.org/apache/cordova-plugin-geolocation.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-geolocation)|
# cordova-plugin-jb-geolocation
ios端是基于cordova-plugin-geolocation稳定版本1.0.0而来,内部调用的是苹果系统自带的定位sdk
安卓端是基于高德定位封装而来,高德sdk为AMap_Location_V4.3.0_20181016.jar
## Installation
This requires cordova 5.0+
cordova plugin add cordova-plugin-jb-geolocation --variable API_KEY=高德定位使用的key
## Supported Platforms
- Android
- iOS
## Methods
- navigator.geolocation.getCurrentPosition
## Objects (Read-Only)
- Position
- PositionError
- Coordinates
## navigator.geolocation.getCurrentPosition
Returns the device's current position to the `geolocationSuccess`
callback with a `Position` object as the parameter. If there is an
error, the `geolocationError` callback is passed a
`PositionError` object.
navigator.geolocation.getCurrentPosition(geolocationSuccess,
[geolocationError],
[geolocationOptions]);
### Parameters
- __geolocationSuccess__: The callback that is passed the current position.
- __geolocationError__: _(Optional)_ The callback that executes if an error occurs.
- __geolocationOptions__: _(Optional)_ The geolocation options.
### Example
```javascript
// 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: ' + 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);
```
### iOS Quirks
Since iOS 10 it's mandatory to provide an usage description in the `info.plist` if trying to access privacy-sensitive data. When the system prompts the user to allow access, this usage description string will displayed as part of the permission dialog box, but if you didn't provide the usage description, the app will crash before showing the dialog. Also, Apple will reject apps that access private data but don't provide an usage description.
This plugins requires the following usage description:
* `NSLocationWhenInUseUsageDescription` describes the reason that the app accesses the user's location.
To add this entry into the `info.plist`, you can use the `edit-config` tag in the `config.xml` like this:
```
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
<string>need location access to find things nearby</string>
</edit-config>
```
### Android Quirks
If Geolocation service is turned off the `onError` callback is invoked after `timeout` interval (if specified).
If `timeout` parameter is not specified then no callback is called.
```
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
ios端是基于cordova-plugin-geolocation稳定版本1.0.0而来,内部调用的是苹果系统自带的定位sdk 安卓端是基于高德定位封装而来,高德sdk为AMap_Location_V4.3.0_20181016.jar 软件开发设计:PHP、QT、应用软件开发、系统软件开发、移动应用开发、网站开发C++、Java、python、web、C#等语言的项目开发与学习资料 硬件与设备:单片机、EDA、proteus、RTOS、包括计算机硬件、服务器、网络设备、存储设备、移动设备等 操作系统:LInux、IOS、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信是一个非常广泛的领域,它涉及到计算机科学、电子工程、数学等多个学科的知识。 云计算与大数据:数据集、包括云计算平台、大数据分析、人工智能、机器学习等,云计算是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息可以按需提供给计算机和其他设备。
资源推荐
资源详情
资源评论
收起资源包目录
ios端是基于cordova-plugin-geolocation稳定版本1.0.0而来,内部调用的是苹果系统自带的定位sdk 安卓端是基于高德定位封装而来,高德sdk为AMap_Location_V4.3.0_20181016.jar.zip (13个子文件)
cm
src
android
Geolocation.java 10KB
libs
AMap_Location_V4.3.0_20181016.jar 351KB
ios
CDVLocation.h 2KB
CDVLocation.m 15KB
LICENSE 11KB
plugin.xml 5KB
package.json 733B
www
geolocation.js 8KB
PositionError.js 1KB
android
geolocation.js 203B
Coordinates.js 2KB
Position.js 1KB
README.md 4KB
共 13 条
- 1
资源评论
普通网友
- 粉丝: 1w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功