branHazz
branHazz

Reputation: 39

working with map areas on android

I need to check if user is close to some custom area. What would be the best approach to create custom areas (I assume using lat and long points) and checking if user is in/near the area on Android?

Thanks

@edit: would Geofencing be a good way of doing this?

Upvotes: 0

Views: 42

Answers (1)

Arora
Arora

Reputation: 113

calculate distance between 2 latitude and longitude points with the below example and you can achieve your objective by using decision statement.

  private String getDistance() {
    String dist = new String();
    Location l1 = new Location("One");
    l1.setLatitude(28.684576);
    l1.setLongitude(77.4859711);

    Location l2 = new Location("Two");
    l2.setLatitude(29.684576);
    l2.setLongitude(78.4859711);

    float distance = l1.distanceTo(l2);
    dist = String.format("%.2f", distance) + " m away";
    distanceMeasure.setText(dist);

    if (distance > 1000.0f && distance <3000.0f) {
//decision statement to check whether second position is near your location
  or not

    }
    return dist;
}

Upvotes: 1

Related Questions