Geofencing in android app - android

I am building a check in and check out application currently. User should be able to check in with the current location and when he goes 50 meters away from the current location he should be checked out.
Can this be implemented using Geo Fencing for android?
I came across this piece of code but do not know how to use:
SimpleGeofence mUIGeofence1 = new SimpleGeofence("1",
Double.valueOf(mLatitude1.getText().toString()),
Double.valueOf(mLongitude1.getText().toString()),
Float.valueOf(mRadius1.getText().toString()),
GEOFENCE_EXPIRATION_TIME,
// This geofence records only entry transitions
Geofence.GEOFENCE_TRANSITION_ENTER);
mGeofenceStorage.setGeofence("1", mUIGeofence1);
I would really appreciate if the correct way to use geo fencing could be given.

You can implement this using geofencing.
The sample code you posted has to do with persisting a Geofence object.
If you want to know how to register a Geofence, check out this presentation on using the geofencing APIs and these android docs. The prezi has some sample code that boils down the use of the APIs to 10 lines of code.

Related

Google PlaceDetectionClient vs FusedLocationProviderClient

My Android app requires the user to enter the current location either by manually searching or by pressing a button to automatically detect the location. I've done the search part using PlaceAutocompleteFragment, but for the detection part I'm confused between the above mentioned classes. To my knowledge, PlaceDetectionClient provides details about the actual building, like a business, and FusedLocationProviderClient uses various sensors to detect the location. Aside from the building detail thing, what's the difference between the two? Which one is more reliable and easier to implement?
It depends on what do you need. If you need user location in your app, better way is to rely on latitude and longitude, so I believe it is better use from FusedLocation which provides exactly what you need.
PlaceDetectionClient is API to detect places where user is nearby i.e check-in feature in current place. I am not sure it is what you really need.

Android: Get current location instead of last known

EDIT: As Francky Vincent said, I see that price depending on distance is not advisable. I have 4 parts but only 3 are the prices depending heavily on the distance (and planning to change it later). But, I still need to get current location as I have 'x.x KM from you'.
A little bit of intro:
When I was around somewhere with low coverage, I open the Grab app and able to get my current location, even though will take too much time. My own app have no problem with location but at the same location, it will get the last known location - and I don't want that since one of my app feature is the price is according to the distance between current location and target.
For the codes, I just using the examples provided for Fused Location by Google in Github and seems like it's not enough? My aim is to get current location instead of last known - just like the Grab app.
Is that possible using Fused Location? Or did the example provided can achieve what I want but I missed something important?
I referred to this question but still got clueless. Really new with this feature.
The strategies that I can come up is:
Start app
Check permission
Request permission
Get current location
Save the latitude and longitude in SharedPreference
Stop getting location
Please help. Thank you!

Notify when user is in my location in Android

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.

Getting notified when user arrives and leaves specific location (Android and iOS)

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.

Geofencing sample app is not working with mock location

greetings
I have a ICE Cream sandwitch phone with google play service.
Installed the Geofencedetection sample app from the following
http://developer.android.com/training/location/geofencing.html
I also installed a Mock Location application
Using this mock location i have set my location as new delhi (lat 28.66 long 77.21).
Now i registered the following geofences using the sample app
Geofence1
lat 11.94898
long 79.48475
radius 1000 meters
Geofence2
lat 77.00000
long 77.00000
radius 1000 meters
Now i again opened the mock location and set the
location as (within geofence 1) my home.
lat 11.94898
long 79.48475
I have checked the mock location with the Maps application.
It displays correctly. I enabled the Allow Mock Locations
in Developer options
But the sample Geofence application is not triggering any
notification. I checked the code. As per the code it should send
notification when the user enters the geofence.
I could not understand why it is not sending notification.
Will this work only on real network?
Please let me know if i am doing anything wrong?
Best Regards
jothi
I had a similar experience using the sample MockLocation app from
http://developer.android.com/training/location/location-testing.html
For example if my geofence is set at 5,100 and I use the mocklocation app to inject a single mock location at 5,100, the geofence will not trigger.
However, if you repeatedly inject multiple mock locations at 5,100 the geofence will trigger. In my case, injecting mock locations at 5,100 three times consecutively caused my geofence to trigger. To be clear, when I say inject I mean doing:
mLocationClient.setMockLocation(yourMockLocation);
Everything below is pure speculation on my part so take it with a grain of salt:
My speculation is there is some filtering algorithm in the LocationClient backend whose purpose is to filter out spurious sensor values and it might be detecting that huge change in lat/long as a possible spurious value. Another possibility is the geofence simply doesnt trigger until it receives multiple readings that indicate you are within its vicinity.
Please check notification of app when app in foreground because i am also not getting any update for geofence in background. But in foreground, It is working fine.
I have stuck with this problem for sometime. Then eventually it turns out the google mock location tutorial (http://developer.android.com/training/location/location-testing.html) failed to mention you will need to set below two calls with the mock location you created:
/*
setElapsedRealtimeNanos() was added in API 17
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
newLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
newLocation.setTime(System.currentTimeMillis());
Without these two calls my mock location won't trigger my geofence. After calling these my geofence is triggered without issues.
I also had a similar experience with MockLocation app, just use a large number of seconds on "send interval" field, like 7 seconds, and the geofence will trigger.
After spending a ton of time on this I finally figured out that the secret was to use the provider name "network" when creating the mock location instance.
Location location = new Location("network");

Categories

Resources