首页 > 解决方案 > 我需要一个蓝点位置,没有 location.getLatitude/Longtitude

问题描述

我有个问题。我的应用程序使用坐标在后续位置之间绘制路径:第一个位置到第二个位置,第二个到第三个位置等。该应用程序绘制路径没有问题,但我的位置有噪音,而且线条无处不在。我知道谷歌地图上的蓝点正在使用平滑算法、不同的位置提供程序和其他调整。我可以获取这个默认蓝点的坐标吗?没有算法就不是法线坐标。

public void onMapReady(GoogleMap map) {

mMap = map;


if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
        == PackageManager.PERMISSION_GRANTED) {
    mMap.setMyLocationEnabled(true);

    lokalizacja();

} else {

    ActivityCompat.requestPermissions(WorkoutActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_LOCATION_REQUEST_CODE);
}


routeOpts = new PolylineOptions()
        .color(Color.BLUE)
        .width(5 /* TODO: respect density! */)
        .geodesic(true);
route = mMap.addPolyline(routeOpts);
route.setVisible(drawTrack);

mMap.setOnMyLocationButtonClickListener(this);
mMap.setOnMyLocationClickListener(this); }

public void lokalizacja() { //Context context = getApplicationContext();

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

locationListener = new LocationListener() {


    @Override
    public void onLocationChanged(Location location) {




        if (routeOpts != null) {                                               
                lat = (float) location.getLatitude();
                lng = (float) location.getLongitude();

            LatLng myLatLng = new LatLng(lat, lng);
            List<LatLng> points = route.getPoints();
            points.add(myLatLng);
            route.setPoints(points);
        }


    }
@Override public void onStatusChanged(String provider, int status, Bundle extras) {

        Log.d("tocos","StatusChanged");
    }

    @Override
    public void onProviderEnabled(String provider) {
        Log.d("tocos","Enabled");
    }

    @Override
    public void onProviderDisabled(String provider) {
        Log.d("tocos","Disabled");
    }
};

标签: androidgoogle-maps

解决方案


我认为您想要的是使用Google Play 服务而不是操作系统附带FusedLocationProvider的内置服务。LocationManager看看这个答案,它非常详细地解释了它


推荐阅读