How to limit the usability of the application in a certain geographical area ANDROID

I want to determine the geographic boundary beyond which the application will refuse to work. I already know how to do this with the square border of two lat / long pairs:

if ((dLAT.doubleValue() > 35.309171) || (dLAT.doubleValue() < 35.226442) || (dLON.doubleValue() < -92.790165) || (dLON.doubleValue() > -92.707081)) { LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this); localBroadcastManager.sendBroadcast(new Intent("killapp")); } 

I also know about geo lenses ... or enough to know that when geoprocessing, areas are defined as circles with a radius from one point.

But, as I said, I would like to determine the boundary that corresponds to reality:

For example, if there was an application that was NOT designed to work, if the user is outside of Kansas, it would be inappropriate to determine RADIUS, since the state of Kansas is not circular and its border is wavy.

I use Android for this, but I doubt it is really important for this issue.

Thanks for any help!

+5
source share
4 answers

This is much simpler than you think:

define a region (s) as a polygon having N points in longitude, latitude coordinates.

Use a point in the polygon method:

Point in Polygon Algorithm

To check if the current point is inside our outer part of the polygon, the x, y coordinates are used in the code above. Just use longitude instead of x and latitude as y.
The code may not work when the region crosses the north or south pole, and when it crosses the snap border (longitude border = -180 to 180), but no one uses your application there.

Despite the fact that it is not always possible to use formulas designed to work in the x, y plane (Cartesian), it works here for spherical lat, lon, coordinates.

+3
source

Here is the official documentation on how you can get the current location of the device and register new location updates: http://developer.android.com/training/location/receive-location-updates.html

Once you have your current location, you can use Location.distanceTo(Location) or Location.distanceBetween(double, double, double, double, float[]) to check if the device is within a given radius.

+1
source

Maybe use Geocoder to extract the city / state name based on your current location, this answer may help you in how to do this.

therefore, if the city / state name is not resolved, you close the application and display a message.

but note that Geocoder requires internet access, but I'm not sure if this suits you.

+1
source

Determine the radius for the location and calculate the distance of the current location in onLocationChangeListener. Set the boolean flag if the distance is less than the radius. Perform your action when the flag is false.

-1
source

All Articles