【问题标题】:Polylines are not filled correctly on google map v2 on android折线未在 android 上的 google map v2 上正确填充
【发布时间】:2014-03-24 23:47:39
【问题描述】:

我在走路/开车时尝试绘制折线(逐点连接),但结果很乱(Image link)。我阅读了here 的建议并做了一些研究,我想出了以下代码来做到这一点:

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);


            SupportMapFragment supportMapFragment = (SupportMapFragment) 
                    getSupportFragmentManager().findFragmentById(R.id.map);

            googleMap = supportMapFragment.getMap();
            googleMap.getUiSettings().setCompassEnabled(false);
            googleMap.getUiSettings().setMyLocationButtonEnabled(true);
            googleMap.setMyLocationEnabled(true);
}

我先从initializeDraw()开始:

private void initializeDraw(){
    rectLine = new PolylineOptions().width(5).color(Color.RED);
    newPolyline = googleMap.addPolyline(rectLine);
}

然后我启动 OnLocationListener(使用 network_provider):

RTlocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, drawLocationOnMap);

locationListener(我从中更新点(lat/lng 并将凸轮聚焦在位置上):

LocationListener drawLocationOnMap = new LocationListener() {

    public void onLocationChanged(Location location) {

        LatLng newPoint = new LatLng(location.getLatitude(), location.getLongitude());

        points = newPolyline.getPoints();
        points.add(newPoint);
        newPolyline.setPoints(points);

        CameraPosition cameraPosition = new CameraPosition.Builder().target(new LatLng(location.getLatitude(), location.getLongitude()))
                .zoom(18)
                .bearing(0)
                .tilt(70)
                .build();
        googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

    };
};

结果: Image link

通过查看上面的图像,即使我走了 100m 直线,它看起来也像“之字形”。对此的任何帮助将不胜感激。

【问题讨论】:

    标签: android map polyline


    【解决方案1】:

    好的,知道了。在获得准确度(使用 getAccuracy() )后,我发现有时它超过 1000m 。经过一番思考,我决定使用 LocationClient 而不是 LocationManager 重写我的位置更新,因为结合使用 GPS 提供商和网络提供商会更准确。

    我遵循了官方的 LocationClient 指南HERE

    【讨论】:

    • 你终于设置了准确度
    猜你喜欢
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 1970-01-01
    相关资源
    最近更新 更多