Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how capturing geolocation with device offline - cordova

I am developing an application using the cordova and found a need to take the data of latitude and longitude of the User, but my application will be used offline (without internet access).

I'm with two questions:

1 - How to check if the unit is active GPS or not?

2 - How I can get the latitude and longitude Offline without internet connection? It's possible?

like image 507
Crazy Avatar asked Jun 08 '15 15:06

Crazy


People also ask

Does geolocation work offline?

Can I Use GPS Without an Internet Connection? Yes. On both iOS and Android phones, any mapping app has the ability to track your location without needing an internet connection.


2 Answers

I´ll try to answer you:

1.- There you have the way to use PhoneGap GeoLication API to check location, and if GPS is enabled. Check this too: Use PhoneGap to Check if GPS is enabled

2.- Yes, the GPS is a satellite system that allows your device to track it´s current position on earth. It´s independent from your Cellphone operator, and then, from the Internet Connection. Then, your device will be able to know it´s position. HTML5 offline mode and geolocation

In addition, you´ll probably need Internet connection to show a map. There are not much solutions for offline maps. Just artisan ones: http://davidrs.com/wp/phonegap-3-0-leaflet-offline-maps/

Hope it helps

REMEMBER: When turning on plane mode, most of devices will turn off GPS antenna too.

like image 187
Alejandro Teixeira Muñoz Avatar answered Nov 07 '22 19:11

Alejandro Teixeira Muñoz


To check if the GPS is available or not you can use this diagnostic plugin - it works for Android and iOS. It can also be used to display the native location settings screen to allow the user to enable location services. For example:

cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
    console.log("GPS is "+(enabled ? "enabled" : "disabled");
    if(!enabled){
        cordova.plugins.diagnostic.switchToLocationSettings();
    }
},function(error){
    console.error("An error occurred: "+ error);
});

As the other answer already states, you can receive a user's location using GPS without needing an internet connection using the geolocation API, but if you want to display a map you'll need a custom solution that doesn't rely on online maps such as Google.

If you want to record the user's location while offline, you can store this information offline in local persistent storage and upload it when the user has an internet connection again. You could use something like lawnchair for the storage.

like image 45
DaveAlden Avatar answered Nov 07 '22 18:11

DaveAlden