Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nativescript/nativescript-geolocation
Geolocation plugin to use for getting current location, monitor movement, etc
https://github.com/nativescript/nativescript-geolocation
android geolocation ios mobile nativescript plugin
Last synced: 13 days ago
JSON representation
Geolocation plugin to use for getting current location, monitor movement, etc
- Host: GitHub
- URL: https://github.com/nativescript/nativescript-geolocation
- Owner: NativeScript
- License: apache-2.0
- Archived: true
- Created: 2015-12-12T12:28:21.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-11-08T15:09:33.000Z (about 1 year ago)
- Last Synced: 2024-04-14T04:51:30.995Z (10 months ago)
- Topics: android, geolocation, ios, mobile, nativescript, plugin
- Language: TypeScript
- Homepage:
- Size: 20 MB
- Stars: 138
- Watchers: 36
- Forks: 77
- Open Issues: 35
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Source moved and managed here:
https://github.com/NativeScript/plugins/tree/main/packages/geolocation# NativeScript Geolocation ![apple](https://cdn3.iconfinder.com/data/icons/picons-social/57/16-apple-32.png) ![android](https://cdn4.iconfinder.com/data/icons/logos-3/228/android-32.png)
[![npm](https://img.shields.io/npm/v/nativescript-geolocation.svg)](https://www.npmjs.com/package/nativescript-geolocation)
[![npm](https://img.shields.io/npm/dm/nativescript-geolocation.svg)](https://www.npmjs.com/package/nativescript-geolocation)
[![Build Status](https://travis-ci.org/NativeScript/nativescript-geolocation.svg?branch=master)](https://travis-ci.org/NativeScript/nativescript-geolocation)Geolocation plugin to use for getting current location, monitor movement, etc.
## Installation
In Command prompt / Terminal navigate to your application root folder and run:
```
tns plugin add nativescript-geolocation
```## Usage
The best way to explore the usage of the plugin is to inspect the demo app in the plugin's root folder.
In `demo` folder you can find the usage of the plugin for TypeScript non-Angular application. Refer to `demo/app/main-page.ts`.In short here are the steps:
### Import the plugin
*TypeScript*
```
import * as geolocation from "nativescript-geolocation";
import { Accuracy } from "tns-core-modules/ui/enums"; // used to describe at what accuracy the location should be get
```*Javascript*
```
var geolocation = require("nativescript-geolocation");
```### Request permissions
```
geolocation.enableLocationRequest();
```### Call plugin methods
````
// Get current location with high accuracy
geolocation.getCurrentLocation({ desiredAccuracy: Accuracy.high, maximumAge: 5000, timeout: 20000 })
````## API
### Properties
#### Location
| Property | Default | Description |
| --- | --- | --- |
| latitude | - | The latitude of the geolocation, in degrees. |
| longitude | - | The longitude of the geolocation, in degrees. |
| altitude | - | The altitude (if available), in meters above sea level. |
| horizontalAccuracy | - | The horizontal accuracy, in meters. |
| verticalAccuracy | - | The vertical accuracy, in meters. |
| speed | - | The speed, in meters/second over ground. |
| timestamp | - | The time at which this location was determined. |#### Options
| Property | Default | Description |
| --- | --- | --- |
| desiredAccuracy? | Accuracy.high | This will return the finest location available but use more power than `any` option. `Accuracy.any` is considered to be about 100 meter accuracy. Using a coarse accuracy such as this often consumes less power. |
| updateDistance | No filter | Update distance filter in meters. Specifies how often to update the location. Read more in [Apple document](https://developer.apple.com/documentation/corelocation/cllocationmanager/1423500-distancefilter?language=objc) and/or [Google documents](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setSmallestDisplacement(float)) |
| updateTime | 1 minute | Interval between location updates, in milliseconds (ignored on iOS). Read more in [Google document](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest#setInterval(long)).|
| minimumUpdateTime | 5 secs | Minimum time interval between location updates, in milliseconds (ignored on iOS). Read more in [Google document](https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest#setFastestInterval(long)).|
| maximumAge | - | How old locations to receive in ms. |
| timeout | 5 minutes | How long to wait for a location in ms. |
| iosAllowsBackgroundLocationUpdates | false | If enabled, UIBackgroundModes key in info.plist is required (check the hint below). Allow the application to receive location updates in background (ignored on Android). Read more in [Apple document](https://developer.apple.com/documentation/corelocation/cllocationmanager/1620568-allowsbackgroundlocationupdates?language=objc) |
| iosPausesLocationUpdatesAutomatically | true | Allow deactivation of the automatic pause of location updates (ignored on Android). Read more in [Apple document](https://developer.apple.com/documentation/corelocation/cllocationmanager/1620553-pauseslocationupdatesautomatical?language=objc)|> If iosAllowsBackgroundLocationUpdates is set to true, the following code is required in the info.plist file:
>```
>UIBackgroundModes
>
> location
>
>```### Methods
| Method | Returns | Description |
| --- | --- | --- |
| getCurrentLocation(options: Options) | Promise | Get current location applying the specified options (if any). Since version 5.0 of the plugin, it will use [requestLocation](https://developer.apple.com/documentation/corelocation/cllocationmanager/1620548-requestlocation?language=objc) API for devices using iOS 9.0+. In situation of poor or no GPS signal, but available Wi-Fi it will take 10 sec to return location. |
| watchLocation(successCallback: successCallbackType, errorCallback: errorCallbackType, options: Options) | number | Monitor for location change. |
| clearWatch(watchId: number) | void | Stop monitoring for location change. Parameter expected is the watchId returned from `watchLocation`. |
| enableLocationRequest(always?: boolean, iosOpenSettingsIfLocationHasBeenDenied?: boolean) | Promise\ | Ask for permissions to use location services. The options are applicable only for iOS. When `always` is true, it opens a custom prompt message and the following keys are required: [NSLocationAlwaysAndWhenInUseUsageDescription](https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationalwaysandwheninuseusagedescription) (iOS 11.0+) OR [NSLocationAlwaysUsageDescription](https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationalwaysusagedescription?language=objc) (iOS 8.0-10.0) and [NSLocationWhenInUseUsageDescription](https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationwheninuseusagedescription). Read more about [request always usage](https://developer.apple.com/documentation/corelocation/cllocationmanager/1620551-requestalwaysauthorization) . When `iosOpenSettingsIfLocationHasBeenDenied` is true, the settings app will open on iOS so the user can change the location services permission. |
| isEnabled | Promise\| Resolves `true` or `false` based on the location services availability. |
| distance(loc1: Location, loc2: Location) | number | Calculate the distance between two locations. Returns the distance in meters. |## Known Issues
### Version Conflicts – Google Play Services
If you have installed multiple plugins that use the Google Play Services you might run into version conflicts. For example, you may encounter the error below when using the [nativescript-google-maps-sdk](https://github.com/dapriett/nativescript-google-maps-sdk) plugin:
```
Cannot enable the location service. Error: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zzbck;
```In order to fix this you might pin the version number in your `app/App_Resources/Android/before-plugins.gradle` file (if the file does not exist, just create it):
```gradle
android {
// other stuff hereproject.ext {
googlePlayServicesVersion = "16.+"
}
}
```## Contribute
We love PRs! Check out the [contributing guidelines](CONTRIBUTING.md). If you want to contribute, but you are not sure where to start - look for [issues labeled `help wanted`](https://github.com/NativeScript/nativescript-geolocation/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22).
## Get Help
Please, use [github issues](https://github.com/NativeScript/nativescript-geolocation/issues) strictly for [reporting bugs](CONTRIBUTING.md#reporting-bugs) or [requesting features](CONTRIBUTING.md#requesting-new-features). For general questions and support, check out [Stack Overflow](https://stackoverflow.com/questions/tagged/nativescript) or ask our experts in [NativeScript community Slack channel](http://developer.telerik.com/wp-login.php?action=slack-invitation).
![](https://ga-beacon.appspot.com/UA-111455-24/nativescript/nativescript-geolocation?pixel)