I have started developing on Android with last Location services feature : Geofences !! Is there any known problem with mock location provider ? Following example here (https://developer.android.com/training/location/geofencing.html) my intent service never fired even if the current location is inside geofence. I'm using FakeGPS android app as mock location provider and if I simulate a route I see the location changes on Google Maps app, so the mock location provider is working well. Any ideas ?
Thanks. Paolo.
An app – very important to note that geofences for 99,9% of the use cases cannot be used without an app. There are some minor exceptions, but most likely, if you are reading this blog post, you will need an application – whether your own or through a partner – that can be utilized for this purpose.
So, why shouldn't we use the Geofencing API? you might ask. The API uses a pay-as-you-go pricing model. After you consume all the initial free requests, the charges are 5.00 USD per 1000 hits.
Building your own geofences might seem like an easy task, but it's important to understand the many challenges involved. While it's possible for developers and product owners to set up geofencing in their apps, many companies come to the best geofencing software providers such as PlotProjects to complete the process.
How geofencing works. To make use of geofencing, an administrator or developer must first establish a virtual boundary around a specified location in GPS- or RFID-enabled software. This can be as simple as a circle drawn 100 feet around a location on Google Maps, as specified using APIs when developing a mobile app.
I tried forever to get this to work. What a pain Google! Since it says geofences can easily be tested using mocks.
The magic trick is to use the provider name "network" in the Location passed to setMockLocation.
Location location = new Location("network");
location.setLatitude(latitude);
location.setLongitude(longitude);
location.setTime(new Date().getTime());
location.setAccuracy(3.0f);
location.setElapsedRealtimeNanos(System.nanoTime());
LocationServices.FusedLocationApi.setMockLocation(_googleApiClient, location);
Actually Intent service used in the mentioned example works good if your app is in foreground but when the app is in background, this IntentService is never called.So we need to use Broadcast-Receiver instead of Intent service.
I found this blog helpful in getting solution.
http://davehiren.blogspot.in/2015/01/android-geofence-stop-getting.html
Geofences use FusedLocationProviderApi so to mock them you have to use FusedLocationProviderApi.setMockLocation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With