Check user inside Map Circle and activate a button

Asked

Viewed 56 times

0

I am developing an application and I came across a logic that I am not able to solve, if someone can give a strength I would appreciate it very much.

inserir a descrição da imagem aqui

I have a destiny that has a range circle of it I made it with this code:

private void setDestino(Double latitude, Double longitude){
    latDestino = latitude;
    longDestino = longitude;
    LatLng destino = new LatLng(latDestino, longDestino);
    map.addMarker(new MarkerOptions().position(destino).title  ("Destino entrega Depósito."));
    CircleOptions circle = new CircleOptions().center(destino);
    circle.fillColor(Color.LTGRAY);
    circle.radius(30); //Em metros.
    map.addCircle(circle);
}

and I have a marker from a user who is going to that destination, he is being updated by picking up the location information from the mobile:

@Override
public void onLocationChanged(Location l) {
    if(l != null){
        latitude = l.getLatitude();
        longitude = l.getLongitude();
        LatLng usuario= new LatLng(latitude, longitude);
        LatLng destino = new LatLng(latDestino, longDestino);
        map.clear();
        map.addMarker(new MarkerOptions().position(usuario).title("Usuário"));
        map.moveCamera(CameraUpdateFactory.newLatLng(usuario));
        setDestino(latDestino, longDestino);
        adicionaPolyline(map, mastertrack, destino);
    }
    map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(l.getLatitude(), l.getLongitude()), 20));

}

The logic I lack is, when the user is outside the circle a button will be disabled, when I click on the target circle I check if the user marker is inside the circle and activate the button.

If anyone knows and can clarify this logic it will be a great favor. Thank you.

  • 1
  • Mathematically speaking: you know the center coordinates of the circle and the user coordinates. It is within the circle if its distance from the center is less than or equal to the radius of the circle.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.