My final goal is to calculate how much time a user is spending at a specific location. Therefore I would like to make the application aware of when a user arrives and leaves a specific location, so I can calculate the time spent there.
Is there a way to get notified when a user arrived at specific location and leaves it in Android and iOS? It does not need to be instant, one-two minutes of miscalculation are fine.
Thank you in advance!
On Android platform, your can try the Geofencing API introduced at Google I/O 2013
Within the API document, they provide a good example project.
And for iOS it's called (surprisingly) Location Services - what you need is the Region Monitoring.
Related
How does one monitor location in the background on Android these days?
We were using a foreground service to do this but with the changes in Android 12 and 13 this does not seem like the right way to achieve continuous location updates and seems like we are getting crashes. Fatal Exception: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false:
Our use case is:
app integrates with a bluetooth speaker and when a button is pressed on the speaker an event is triggered in the app. The app calculates a distance and sends that back to the speaker to be announced. We are calculating the position between the phone and another known location (LatLng). So we need to keep track of the users current position in order to calculate the distance at any point in time. A user could be doing this for a couple hours without opening their phone.
I have been trying to find good resources on how to monitor location in the background but is a bit tricky to find any resources that take into account the recent changes from the OS and newer Android APIs.
It seems like WorkManager would be an appropriate solution but I am not sure about hitting work restrictions when trying to monitor location for an extended time.
Any and all help / resources appreciated.
I know that there is a technique to update more than 100 geofence to google api client. But I want a complete solution to add more than 100 geofence or any library to achieve it. I already done my project using google api client. But there is limitation off 100 geofence only.
Is there any library or any other technique to update more than 100 geofence?
And all these process should run in background. I mean even after application process is killed, this should run in background. Is it possible?
Thanks in advance.
The issue with having more than 100 geofences is that depending on how close they are in proximity to the user and how many geofences you actually have, it can become a serious battery drain due to constant location polling. I'm not sure how you plan to implement your geofences, but I would suggest you look into loading only geofences within your immediate and surrounding area, storing the rest into a database, and loading/unloading depending on your current location and distance from the edge of the geofences. Bing came up with this nice tiling system that may come in handy for you.
I am in the process of planning an app that includes a feature that requires it to record and store the exact route a user takes while driving. Is there any location api that supports this out of the box? Or supports detecting a turn? I was initially hoping for an event triggered by the user turning onto a different road, but so far, no such luck.
I think you may try this way:
1 Request for GPS location update every 30s ,you can do this with Timer and TimerTask ,and LocationManager;
2 You can get the road name through Google Map API with the GPS location you get;
3 So you will get to know whether the user is turning onto a different road every 30 seconds.
I believe I have found a solution that makes use of the other answer here. I will post it as a separate answer though as it adds more to the other answer and is a full solution. As Ai Hao said, I could have my app request an updated location every 30 seconds to determine whether the user is on a new road, and then place a waypoint signalling the turn. However, this method is flawed if the mapping algorithm used (and I do not have the expertise to write my own) detects multiple possible routes. My solution to this issue is to store all location responses until a turn is made. This means that when a turn is detected, the oldest location data will be the last turn, while the newest will correspond to the turn being made. The app will request alternate routes, and if any are found, will calculate a route between the second oldest and second most recent coordinates, until no alternate routes are found. This should result in the exact route that the user took.
I read in the documentation that I can setup geofencing so I know when the user entered/left the geofenced area.
However, I was wondering, can't I get the same behaviour by just taking my current location (ona regular location update) and check the distance with the center of the intended geofence. If it is less than a certain radius then I am within that area.
Wouldn't that have the same effect (infact way less code than geofence)?
Thank you
I believe the advantage of a geofence as opposed to what you describe, is that geofences are objects that come with a lot of extra support in Google Play Services. Using geofences allows multiple different Activities or even Applications to get notifications/callbacks from a single (or set of) geofence objects created elsewhere. These callbacks will happen automatically even if you are in another application because Google Play Services can monitor location in the background without you writing additional code in your Activity, and they can expire on their own. Doing this would be more difficult if you were to roll your own distance calculations as you would have to set it up your own Service framework.
From this answer by CommonsWare:
Geofences are designed to work even without your application running.
However, if your goal is only to check whether you are a certain distance from a geographical point (without caring about what happens when the user goes to check their email or puts their phone back in their pocket), then what you describe might be easier.
I am looking for an easy way to check if a user is at my location (50m) radius if notify me.
Right now I have a service running every two minutes getting position of each user comparing it and then notifying if user in same location.
Can this be done using promixityalert: http://goo.gl/9I857T?
Thanks!
Instead ProximityAlert I would use Geofences.
http://developer.android.com/training/location/geofencing.html
Is newer and does a more effective use of the battery
In your case, you can have a service that sends to the other device the current location every X minutes, so it can update the Geofence. The problem that I see is that there would be a lot of calls, spending battery and the data plan.
A good approach is to use the Location Services API, you can detect if a user is standing or moving.
http://developer.android.com/training/location/activity-recognition.html
Using this and sending new locations only when the user is moving you will be able to reduce the amount of calls.
Parse is another option as #thepace mention. It is easy to use and whit it would be easy to implement what you are trying to do, but is not free :(
Hope it helps.
Issue: Check if any user (multiple and variable location) is within specific radius of my current location(variable).
Solution:
1. Parse.com
a) Ensure every user has their location updated in Parse DB including yours.
https://parse.com/tutorials/anywall-android
b) Use push notificaitons: https://parse.com/docs/push_guide#setup/Android
1> Create a channel wherein only you are subscribed.
2> Create your installation query and send notification to it to the channel subscribed.