androidgoogle-mapsgoogle-latitude

how can I know if a latitude and longitude are close to my current location using google android api?


I just want to know how to use google android api to get my current location, display the location and compare that location with others latitudes and longitudes.


Solution

  • Check out the android docs for everything you should need on location. So for example first you would get the current location like this

    @Override
    public void onConnected(Bundle connectionHint) {
        mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
                mGoogleApiClient);
        if (mLastLocation != null) {
            mLatitudeText.setText(String.valueOf(mLastLocation.getLatitude()));
            mLongitudeText.setText(String.valueOf(mLastLocation.getLongitude()));
        }
    }
    

    then you would compare that with the other location using the method distanceBetween(Location dest)

    Hope this helps.