How can I compare geographical coordinates in android studio and google maps

0

I have a variable with which I get my location and now I want to compare my location with a fixed marker How can I do it? I try to do this

protected void startLocationUpdates() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    PendingResult<Status> pendingResult = LocationServices.FusedLocationApi
            .requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
    Log.d(TAG, "Location update started ..............: ");
}


private void prueba() {
    if (mLocationRequest == es igual a la posision fija) {

    }
}
    
asked by Francisco Navarrete 21.02.2018 в 10:25
source

1 answer

-1

Create a new Location object with the coordinates of your marker and then use distanceTo to calculate if the distance between the user and your marker is within a given range that will be your margin of error, for example, 50 meters.

private static double THRESHOLD = 50.0;

...

Location markerLocation = new Location("");
markerLocation.setLatitude(marker.getPosition().latitude);
markerLocation.setLongitude(marker.getPosition().longitude);

if (mLocationRequest.distanceTo(markerLocation) < THRESHOLD) {
  ...
}
    
answered by 21.02.2018 в 11:04