Question

I am asking advice on the best way to create a geofence application for android application using google maps.

I have looked at the sample code given on the android documentation but I am not sure if this satisfys what I wish to do. Basically I wish to show the user location and a radius and alert if the user goes outside this radius. The size of the radius is dynamic and can be dependant upon the time of day.

Could anyone give me any good starting points on what I should be looking at please? I know this is a general question but I am seeking advice on the best way to achieve this not for someone to supply code and give me it.

Thank you

Was it helpful?

Solution

User location can be obtained using GPS and as you said radius is dynamic and is dependent on time, so radius can be figured out from time. Now you have user location and radius. Now, you can calculate distance of user location from center of circular geofence and then compare it with radius.

Distance calculation between two points over map can be done using API like "distanceTo" available in developer website. http://developer.android.com/reference/android/location/Location.html

If radius is bigger than distance, user is inside the geofence and if radius is smaller than calculated distance, then user is outside of dynamic geofence.

For more info regarding implementation- visit http://developer.android.com/training/location/geofencing.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top