I am developing a Phonegap application which requires GPS tracking. The tracking is required only at a certain time. For example, the event start at 5 o clock, then I want to start tracking at 5 o clock only. Any option for doing it background. The app is developing for iOS and Android.
Is there any option for doing this. Any help would be appreciated. Thanks in advance.
Maybe this will help you -> Can i schedule events in Phonegap but i think, this will only work on Android. I don't know how you could realise this on iOS.
You can use AlermManager class in that create broadcast when broadcast wakeup then u can call
gps enable and track location according to that same for stop gps location also
Related
I'm working on Android project that related to GPS I still new to android so I don't know a lot about it.
My project is an app where it calculates the distance between user location and a specified other location so if the distance is less than (X) say 1KM the app will send a notification to the user.[[I know how to calculate the distance between two
locations]].
My problem is: how can I do this even if the user didn't open the app (I mean if there's anyway that I can make the app calculates the distance in the background while the app is closed).so I want the GPS feature works in the background.
Thanks in Advance.
You can use a service for background process.
For your question for getting location, you should try these links:
Best way to get user GPS location in background in Android
Get GPS location via a service in Android
My solution for this problem was simply :-
you can use Services for working in the background (when the Activity isn't showing)
check this : -Get GPS location via a service in Android
**if you want this service to run for ever, even if the app is closed/killed you can use broadcast receivers **
To get the app to run in the background, you'll need to learn about a service.
Service is a service that causes applications to run in the background such as gps, notification and more ..
link:
https://developer.android.com/reference/android/app/Service.html
User services. They are simple to use and all you need.
Here is the documentation.
A service is another component of an android application (like activity). You need to define the service in manifest. After that you could start the device using startService (intent). If you need to take some info (communicate with one activity) you can use bindService instead of startService. (Also need to implement onBind).
Another solution is to sendData using a broadcast receiver. Or you can simple set a notification in service and use it.
I have no knowledge in android development nor in ios apps.
Is there a way to get the user's location without my app (android/ios) being open in the background (with the user's acceptance)?
Thanks!
Yes you can have an Android Service that listens for location changes. See LocationManager in service as one example. Depending one what you are doing, the question is how should you start your service.
I am working with the Geofence API Sample application I've got it running and seems to work alright. I did make the modifications to it to use BroadcastReceiver instead of the IntentService.
But I will only get the notifications if I have some other app open that is using GPS such as Maps, or GPS Tester app.
If I don't have one of those apps open and I walk into the geofence zone nothing happens. But as soon as I launch one of them I will get the notification within a few seconds.
I ended up creating a service that forces the GPS to stay active by requesting location updates on a relatively quick interval.
While this is admittedly a poor work around for a "real" application. It worked for my purposes. In which I needed to be able to present a working proof of concept to an audience, which impeded my ability to use a geo points which were further spread out.
Even I too had a struggle with getting Geofence notification as soon I entered Geofence or Exit the one.There were always delays in notifications until I found a really nice Location Library called little-fluffy-location-library which serves my purpose.Location updates will be broadcast to your app periodically.
According the Documentation it says that:
The library works by using Froyo's passive location listener (only possible with Android 2.2 and up, hence why it works best with it), which listens to location updates requested by other apps on your phone. The most accurate location is broadcast to your app approximately every 15 minutes. If a location update hasn't been received from another app for an hour, the library forces a location update of its own.
I think you should give a try with this Library and Let me know if it works for you!!
Theoretic question.
In my app I need to create alarm at location functionality.
So user can pick location, set alarm and any time while She/He
will get closer to location alarm will trigger.
I know that I have to create Service to listen the current
location. It is obvious that I can't use GPS.
Any ideas how to figure it out if device is close to location?
I know that I still have Network location, which probably I will
use, but I afraid of that this will consume to much energy.
If there is any internal android system service which provide such
data? That I can just setup receiver.
Any ideas are welcome ;)
I suggest building on Google Play Services in order to get the product working quickly. Of course if you need to target non-Google phones, then program this manually, but only if you have to.
Play offers Geofencing apis - here are the docs:
Creating and Monitoring Geofences
PROS:
Google is constantly updating the Play sdk to optimise the features.
quick to get it working
battery efficiency
CONS:
it will not work on non-Google API devices, i.e. Kindle Fire
Upshot of all this:
if your app relies on Google Maps at all, then use the Play Geofencing.
I decided to use ProximityAlarm in Service.
Great example from this post:
Android GPS proximity alert not working
I am trying to make an app , where if the user enters a particular region, he will get an alert. And that will work even if the app is in background.
I found Ti.App.iOS.backgroundService to do that for iphone but how to start the background service in android and how to present local notification kind thing when particular latitude and longitude is found.
so basically my questions are :-
background location service in android
android equivalent for localnotification
For background geo on Android I use the below strategy.
1) In my app.js I add an Titanium.App.addEventListener that contains my geo logic
Kitchen Sink Sample https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/app_events.js
2) I then create a ServiceIntent that fires every 15 minutes
Kitchen Sink Sample https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/android_services.js
Please note this service.js you call needs to be in your android folder, even if you have an android only project.
3) The service checks if the individual has moved more then 1KM, if they have it fires the App Event defined in step 1.
Using this strategy and adjusting my service time and distance calculation I've been able to reduce most of my battery drain issues that I had with the built in location event with distance filter.
Hope this helps.