Skip to content

Commit 2db8a4a

Browse files
committed
First commit
0 parents  commit 2db8a4a

22 files changed

+5542
-0
lines changed

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
root: true,
3+
parserOptions: {
4+
ecmaVersion: 2016,
5+
sourceType: 'module',
6+
}
7+
}

.gitignore

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# node-waf configuration
17+
.lock-wscript
18+
19+
# Compiled binary addons (http://nodejs.org/api/addons.html)
20+
build/Release
21+
22+
# Dependency directory
23+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
24+
node_modules
25+
npm-debug.log
26+
27+
# OSX
28+
#
29+
.DS_Store
30+
31+
# Xcode
32+
#
33+
build/
34+
*.pbxuser
35+
!default.pbxuser
36+
*.mode1v3
37+
!default.mode1v3
38+
*.mode2v3
39+
!default.mode2v3
40+
*.perspectivev3
41+
!default.perspectivev3
42+
xcuserdata
43+
*.xccheckout
44+
*.moved-aside
45+
DerivedData
46+
*.hmap
47+
*.ipa
48+
*.xcuserstate
49+
project.xcworkspace
50+
51+
# Android/IJ
52+
#
53+
react-native-dialogs.iml
54+
.idea
55+
.gradle
56+
local.properties
57+
android/*.iml
58+
59+
~assets/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Alberto Martínez
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# react-native-cross-geolocation
2+
3+
[![npm][npm-image]](https://www.npmjs.com/package/react-native-cross-geolocation)
4+
[![License][license-image]](LICENSE)
5+
6+
React Native Geolocation complatible module that uses the new Google Location API in Android devices.
7+
8+
This module is for React Native 0.50.x using the Google Gradle plugin 3.1.2 or later.
9+
10+
## Setup
11+
12+
```bash
13+
$ yarn add react-native-cross-geolocation
14+
$ react-native link react-native-cross-geolocation
15+
```
16+
17+
JavaScript import:
18+
```js
19+
import Geolocation from 'react-native-cross-geolocation'
20+
```
21+
22+
### Configuration and Permissions
23+
24+
This section only applies to projects made with `react-native init` or to those made with Create React Native App which have since ejected. For more information about ejecting, please see the [guide](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) on the Create React Native App repository.
25+
26+
#### iOS
27+
You need to include the NSLocationWhenInUseUsageDescription key in Info.plist to enable geolocation when using the app. Geolocation is enabled by default when you create a project with react-native init.
28+
29+
In order to enable geolocation in the background, you need to include the 'NSLocationAlwaysUsageDescription' key in Info.plist and add location as a background mode in the 'Capabilities' tab in Xcode.
30+
31+
#### Android
32+
To request access to location, you need to add the following line to your app's AndroidManifest.xml:
33+
34+
```xml
35+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
36+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
37+
```
38+
39+
Android API >= 18 Positions will also contain a `mocked` boolean to indicate if position was created from a mock provider.
40+
Android API >= 23 Permissions are handled automatically.
41+
42+
#### Methods
43+
- [`setRNConfiguration`](#setrnconfiguration)
44+
- [`requestAuthorization`](#requestauthorization)
45+
- [`getCurrentPosition`](#getcurrentposition)
46+
- [`watchPosition`](#watchposition)
47+
- [`clearWatch`](#clearwatch)
48+
- [`stopObserving`](#stopobserving)
49+
50+
## Reference
51+
52+
### Methods
53+
54+
#### `setRNConfiguration()`
55+
```js
56+
Geolocation.setRNConfiguration(config);
57+
```
58+
59+
Sets configuration options that will be used in all location requests.
60+
61+
Parameters:
62+
63+
NAME | TYPE | REQUIRED | DESCRIPTION
64+
---- | ---- | -------- | -----------
65+
config | object | Yes | See below.
66+
67+
Supported options (optionals):
68+
69+
- `skipPermissionRequests` (boolean, iOS-only) - Defaults to `false`. If `true`, you must request permissions before using Geolocation APIs.
70+
- `lowAccuracyMode` (number, Android-only) - Defaults to LowAccuracyMode.BALANCED.
71+
- `fastestInterval` (number, Android-only) - Defaults to 10000 (10 secs).
72+
- `updateInterval` (number, Android-only) - Defaults to 5000 (5 secs).
73+
74+
#### `requestAuthorization()`
75+
```js
76+
Geolocation.requestAuthorization();
77+
```
78+
Request suitable Location permission based on the key configured on pList. If NSLocationAlwaysUsageDescription is set, it will request Always authorization, although if NSLocationWhenInUseUsageDescription is set, it will request InUse authorization.
79+
80+
#### `getCurrentPosition()`
81+
```js
82+
Geolocation.getCurrentPosition(geo_success, [geo_error], [geo_options]);
83+
```
84+
85+
Invokes the success callback once with the latest location info.
86+
87+
Parameters:
88+
89+
NAME | TYPE | REQUIRED | DESCRIPTION
90+
---- | ---- | -------- | -----------
91+
geo_success | function | Yes | Invoked with latest location info.
92+
geo_error | function | No | Invoked whenever an error is encountered.
93+
geo_options | object | No | See below.
94+
95+
Supported options:
96+
97+
- `timeout` (ms) - Defaults to MAX_VALUE
98+
- `maximumAge` (ms) - Defaults to INFINITY.
99+
- `enableHighAccuracy` (bool) - On Android, if the location is cached this can return almost immediately, or it will request an update which might take a while.
100+
101+
#### `watchPosition()`
102+
```js
103+
Geolocation.watchPosition(success, [error], [options]);
104+
```
105+
106+
Invokes the success callback whenever the location changes. Returns a `watchId` (number).
107+
108+
Parameters:
109+
110+
NAME | TYPE | REQUIRED | DESCRIPTION
111+
---- | ---- | -------- | -----------
112+
success | function | Yes | Invoked whenever the location changes.
113+
error | function | No | Invoked whenever an error is encountered.
114+
options | object | No | See below.
115+
116+
Supported options:
117+
118+
- `timeout` (ms) - Defaults to MAX_VALUE.
119+
- `maximumAge` (ms) - Defaults to INFINITY.
120+
- `enableHighAccuracy` (bool) - Defaults to `false`.
121+
- `distanceFilter` (m)
122+
- `useSignificantChanges` (bool) (unused in Android).
123+
124+
#### `clearWatch()`
125+
```js
126+
Geolocation.clearWatch(watchID);
127+
```
128+
129+
Parameters:
130+
131+
NAME | TYPE | REQUIRED | DESCRIPTION
132+
---- | ---- | -------- | -----------
133+
watchID | number | Yes | Id as returned by `watchPosition()`.
134+
135+
#### `stopObserving()`
136+
```js
137+
Geolocation.stopObserving();
138+
```
139+
140+
Stops observing for device location changes. In addition, it removes all listeners previously registered.
141+
142+
Notice that this method has only effect if the `geolocation.watchPosition(successCallback, errorCallback)` method was previously invoked.
143+
144+
## TODO
145+
146+
- [X] Enhanced docs
147+
- [ ] Tests
148+
149+
[npm-image]: https://img.shields.io/npm/v/react-native-cross-geolocation.svg
150+
[license-image]: https://img.shields.io/npm/l/express.svg

android/build.gradle

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
import groovy.json.JsonSlurper
3+
4+
// dynamically retrieve version from package.json
5+
def computePackageVersion() {
6+
def slurper = new JsonSlurper()
7+
def json = slurper.parse(file('../package.json'), 'utf-8')
8+
return json.version
9+
}
10+
11+
/*
12+
Google Play Services 12.0.x to 15.0.x depends on support libraries 26.1.0
13+
*/
14+
def DEF_PLAY_SERVICES_VERSION = '15.0.1'
15+
def DEF_BUILD_TOOLS_VERSION = '27.0.3'
16+
def DEF_MIN_SDK_VERSION = 21
17+
def DEF_COMPILE_SDK_VERSION = 27
18+
def DEF_TARGET_SDK_VERSION = 27
19+
20+
def _playServicesVersion = rootProject.hasProperty('googlePlayServicesVersion') ? rootProject.googlePlayServicesVersion : DEF_PLAY_SERVICES_VERSION
21+
def _buildToolsVersion = rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEF_BUILD_TOOLS_VERSION
22+
def _minSdkVersion = rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : DEF_MIN_SDK_VERSION
23+
def _compileSdkVersion = rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEF_COMPILE_SDK_VERSION
24+
def _targetSdkVersion = rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEF_TARGET_SDK_VERSION
25+
26+
buildscript {
27+
repositories {
28+
mavenLocal()
29+
google()
30+
jcenter()
31+
}
32+
dependencies {
33+
classpath 'com.android.tools.build:gradle:3.1.3'
34+
}
35+
}
36+
37+
apply plugin: 'com.android.library'
38+
39+
android {
40+
compileSdkVersion _compileSdkVersion
41+
buildToolsVersion _buildToolsVersion
42+
43+
defaultConfig {
44+
minSdkVersion _minSdkVersion
45+
targetSdkVersion _targetSdkVersion
46+
versionCode 1
47+
versionName computePackageVersion()
48+
}
49+
lintOptions {
50+
abortOnError false
51+
}
52+
compileOptions {
53+
sourceCompatibility JavaVersion.VERSION_1_7
54+
targetCompatibility JavaVersion.VERSION_1_7
55+
}
56+
}
57+
58+
repositories {
59+
mavenLocal()
60+
google()
61+
jcenter()
62+
maven { url "$rootDir/../node_modules/react-native/android" }
63+
}
64+
65+
dependencies {
66+
compileOnly 'com.facebook.react:react-native:+'
67+
implementation "com.google.android.gms:play-services-location:$_playServicesVersion"
68+
}
53.4 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Sat Jun 16 18:52:01 CDT 2018
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

0 commit comments

Comments
 (0)