Saxophonist
Saxophonist

Reputation: 707

PhoneGap - Request GPS Activation

I am developing a Phonegap app for Android and would like to get coordinates from GPS.

The application is composed of the Web assets and a Background service (Java).

I get these coordinates from Java side.

But I believe from the backgorund service is not possible to request the user to turn GPS on.

How could I request to the user activate the GPS, using that standard intent for activating it? And Is that possible ?

Upvotes: 1

Views: 2921

Answers (2)

DaveAlden
DaveAlden

Reputation: 30366

You could use this Diagnostic plugin for Phonegap Android.

The isGpsEnabled function allows you to check if GPS is enabled on the Android device and switchToLocationSettings switches from your app to the Location settings page where the user can switch on GPS (this should be probably be preceded by a dialog asking if the user wants to do this).

Update I've forked the original plugin, updated it for Phonegap/Cordova 3+, documented it and extended its functionality. It can be found here: https://github.com/dpa99c/cordova-diagnostic-plugin

Upvotes: 4

Andrew Lively
Andrew Lively

Reputation: 2153

The first time you use the Geolocation API it will ask the user for permission. Other than that you will just have to listen if the GPS is active, and if it's not you'll have to display a message requesting them to grant you GPS access, usually followed by instructions on how to do that through the device settings.

Upvotes: 2

Related Questions