Reputation: 397
I am trying to develop an android app where I want to get the following details from google maps API.
Is it possible to set geofensing (either rectangular or circular) for particular place using paid version of google maps API?. If yes, then what is the accuracy I can get from google maps API (interns of meters or feet for particular place).
Can I be able to read how long user stayed at particular place using google maps API?.
When user stayed for some time at particular place (as stated in point 2), is it possible for android OS to notify my app in that mobile?
For all above three features do I have to opt for paid version of google maps API?. OR it can be done using free version of google maps API as well?.
Upvotes: 0
Views: 88
Reputation: 111
For all three question the answer is yes. The first one, you can determine the accuracy you want to get in the Builder of Geofence, like this
new Geofence.Builder()
.setRequestId(key)
.setCircularRegion(lat, lang, 150)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
.setLoiteringDelay(1000)
.build();
I set the accuracy for 150m(there is one thing you should know is that the more accuracy you set the more power you use)
For the second and third one, you can set the TransitionTypes to Geofence.GEOFENCE_TRANSITION_DWELL to know whether the user is stay in one place for a time. At the same time, you can use PendingIntent to send a broadcast when this condition match. The complete code is as below
Geofence geofence = getGeofence(lat, lng, key);
geofencingClient.addGeofences(
getGeofencingRequest(geofence),
getGeofencePendingIntent(title, location, id))
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
}else{
}
});
The code of getGeofencingRequest
private GeofencingRequest getGeofencingRequest(Geofence geofence) {
GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
builder.addGeofence(geofence);
return builder.build();
}
The code of getGeofencePendingIntent
private PendingIntent getGeofencePendingIntent(String title, String location, long id) {
Intent i = new Intent("add your unique ID for the broadcast");
Bundle bundle = new Bundle();
bundle.putLong(Reminder.ID, id);
bundle.putString(Reminder.LOCATION_NAME, location);
bundle.putString(Reminder.TITLE, title);
i.putExtras(bundle);
return PendingIntent.getBroadcast(
getContext(),
(int) id,
i,
0
);
}
Upvotes: 1