6

I'm writing an app that needs to determine whether a user falls within one of several defined zones (based on gps location).

The Google maps javascript API has an easy to use function containsLocation(). However I want to be able to do this from an app on android, not a web-based service. Does anyone know if such a call exists in the android version of maps? Any pointers will be helpful!

aguywithsocks
  • 61
  • 1
  • 4
  • There is `LatLngBounds.contains()`, but only for "square" areas. What is the shape of these zones? – matiash Dec 18 '14 at 22:39
  • Thanks. I know of `LatLngBounds.contains()`, but these zones are not square, unfortunately. – aguywithsocks Dec 18 '14 at 22:53
  • What are they exactly? :) If circles, you can just calculate distance to the center. If polygons, try http://stackoverflow.com/questions/14405593/polygon-touch-detection-google-map-api-v2 – matiash Dec 18 '14 at 22:56
  • Yes, that is something you can do without any services. Lat and lng are just numbers; you can calculate something like Pythagoras (you have to multiply the longitude by cosinus(lat) ). How are these zones defined? – Emmanuel Delay Dec 19 '14 at 09:50

2 Answers2

5

A bit late, but here's the answer: com.google.maps.android.PolyUtil.containsLocation() from Google Maps Android API utility library.

Uli
  • 2,828
  • 20
  • 23
2

You can use the Geofencing feature for this purpose. The API's for that are a part of Google Play Services library and hence you can start using it by importing it into your app project.

It even gives the notification if a particular user has entered or exited a specific geofencing location in order for a developer to monitor the number of mobile devices entered in the zone he defined. The implementation is pretty simple, I am pasting some links that may guide you further.

This is Google's official documentation about Geofencing: http://developer.android.com/training/location/geofencing.html

This link actually implements an app for geofencing.

And this is another link if you want to use a third party plugin in order to get geofencing in your app.

Hope this would help!!!

AniV
  • 3,997
  • 1
  • 12
  • 17