简体   繁体   English

具有准确度的Google Maps自定义MyLocation标记

[英]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. 我在应用程序中使用Google Maps,并使用自定义标记显示用户的位置。
I receive location updates with Fuse Location API and just redraw the marker when user's location is changed. 我使用Fuse Location API接收位置更新,只是在更改用户位置时重新绘制标记。
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();
    }

You can use the Location.getAccuracy method. 您可以使用Location.getAccuracy方法。 From the documentation 文档中

Get the estimated accuracy of this location, in meters. 获取此位置的估计精度,以米为单位。

We define accuracy as the radius of 68% confidence. 我们将精度定义为68%置信度的半径。 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. 换句话说,如果您绘制一个以该位置的纬度和经度为中心且半径等于精度的圆,则真实位置在该圆内的可能性为68%。

Thus, you can use the returned value as the radius of the circle centered that location to draw an approximated accuracy circle. 因此,您可以使用返回值作为以该位置为中心的圆的半径来绘制近似精度的圆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM