7

When starting my app, several POI coordinates shall be added to the Android System. Some hours later, my app is closed and the user walks close to one of the POI he shall get notified e.g. through a status message.

Is this the right approach for my scenario? Are there more things available in Android to achieve this?

public void addProximityAlert (double latitude, double longitude, float radius, long expiration, PendingIntent intent)

OneWorld
  • 17,512
  • 21
  • 86
  • 136

1 Answers1

14

Yes, you would use LocationManager and addProximityAlert() as the basis for your desired feature.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Sir, is this the same as to how geofence works? I have never used geofence though i am trying to figure out how it works without it calling on gps to track the current location. If given locationmanager and geofence, then which one should be selected? – Rat-a-tat-a-tat Ratatouille Sep 30 '14 at 05:15
  • @Rat-a-tat-a-tatRatatouille: Proximity alerts never worked all that well. If you can live with the dependency on Google Play Services, using `LocationClient` and geofencing may give you better results. – CommonsWare Sep 30 '14 at 10:56
  • i have had an experience with the proximity alert, doesnt work on emulators :(. And i get an error 1000 while adding geofencing and i dont know why also :(.. – Rat-a-tat-a-tat Ratatouille Sep 30 '14 at 11:06
  • Sir, error 1000 since the location service and gps was off. i will experiment with geo-fencing when i travel home today – Rat-a-tat-a-tat Ratatouille Sep 30 '14 at 11:12
  • Sir, i am really sorry for so many questions, bt i am still not clear though, does geofencing handle location updates on its own ? Since with location client we can get the last known location – Rat-a-tat-a-tat Ratatouille Oct 01 '14 at 05:01
  • @Rat-a-tat-a-tatRatatouille: I have not used the geofencing APIs. Please ask a separate Stack Overflow question. – CommonsWare Oct 01 '14 at 10:40
  • Don't we need to keep asking for location updates in case of addProximityAlert ? – Ajay S Feb 15 '18 at 16:00
  • @AjayS: To be honest, I forget. I have not looked at proximity alerts much since I wrote this answer ~7 years ago. – CommonsWare Feb 15 '18 at 16:02