Leo DroidCoder
Leo DroidCoder

Reputation: 15046

Google Maps custom MyLocation marker with accuracy level

I am using Google Maps in the application and show user's location with a custom marker.
I receive location updates with Fuse Location API and just redraw the marker when user's location is changed.
It works fine, but the question is how to implement accuracy circle which we can see on default marker (semi-transparent blue dynamic circle around the user's marker)? Drawing a circle is not a problem, the problem is how to get current location accuracy radius.

Thanks in advance for any piece of advice.

And some code on how it currently works:

 // here is the Api client
 private synchronized void buildGoogleApiClient() {
        Log.i(LOG_TAG, "Building GoogleApiClient");
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
        createLocationRequest();
    }


    protected void createLocationRequest() {
        mLocationRequest = new LocationRequest();
        mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
        mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        }

    @Override
    public void onLocationChanged(Location location) {
        // update user location (redraw marker and animate camera)
        updateMyLocation();
    }

Upvotes: 0

Views: 847

Answers (1)

antonio
antonio

Reputation: 18242

You can use the Location.getAccuracy method. From the documentation

Get the estimated accuracy of this location, in meters.

We define accuracy as the radius of 68% confidence. In other words, if you draw a circle centered at this location's latitude and longitude, and with a radius equal to the accuracy, then there is a 68% probability that the true location is inside the circle.

Thus, you can use the returned value as the radius of the circle centered that location to draw an approximated accuracy circle.

Upvotes: 2

Related Questions