【问题标题】:Polylines on android map disappear when zoomed outandroid地图上的折线在缩小时消失
【发布时间】:2013-08-05 01:07:19
【问题描述】:

我正在使用下面的代码在 Google 地图(android API v2)上以 5 度间隔绘制一堆垂直线。一切都很好,直到缩小到大约缩放级别 5.1,此时我的所有线条都消失了。这是我的代码中的错误,还是地图 API 故意做的事情?如何让这些线条在所有缩放比例下都显示?

非常感谢。

if (gMap != null)   {
            double lat = loc_service.getLatitude();
            double lng = loc_service.getLongitude();
            LatLngBounds bounds = new LatLngBounds(new LatLng(lat-(MAP_WIDTH/2), lng-(MAP_WIDTH/2)), new LatLng(lat+(MAP_WIDTH/2), lng+(MAP_WIDTH/2)));
            CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 720, 720, 0);
            gMap.setMyLocationEnabled(true);
            gMap.moveCamera(cu);

            // initialize the time marker AT ONE  MINUTE INTERVALS
            time_markers = new ArrayList<Polyline>();
            // calculate distance to zero-second mark
            double offset = getLngOffset();
            for (int i=-MARK_RNG; i<MARK_RNG; i++)  {
                PolylineOptions plOptions = new PolylineOptions()
                    .add(new LatLng(90, (lng-offset + (i*5))))
                    .add(new LatLng(-90, (lng-offset + (i*5))))
                    .width(2)
                    .color(Color.BLUE);

                time_markers.add(gMap.addPolyline(plOptions));
            }
        }

【问题讨论】:

    标签: android google-maps polyline


    【解决方案1】:

    这似乎是 Google Play 服务库中的一个错误,类似于前段时间的the one I reported

    我刚试过

    map.addPolyline(new PolylineOptions()
            .add(new LatLng(90, 5))
            .add(new LatLng(-90, 5))
            .width(2)
            .color(Color.BLUE));
    

    它会在低缩放级别下从0,00,5 画一条线,在您放大后从0,590,5 画一条线。两者当然都不正确。

    解决方法是改用85

    map.addPolyline(new PolylineOptions()
            .add(new LatLng(85, 5))
            .add(new LatLng(-85, 5))
            .width(2)
            .color(Color.BLUE));
    

    但不要问我为什么这样可以正常工作...

    您可能还想在链接的问题报告中添加更多信息。

    【讨论】:

    • 您的 85/-85 修复完成了这项工作 - 谢谢。也许 90/-90 在投影之外(我记得在某处读到地图本身仅位于 +/- 85 度纬度)。我会将我的问题添加到错误报告中,希望得到答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-03
    • 1970-01-01
    • 2015-03-27
    • 1970-01-01
    • 2019-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多