1

我一直在研究 nutiteq 地图,但随着位置的变化,我无法绘制折线。

到目前为止我尝试过:

@Override
public void onLocationChanged(Location location)
{
    MapPos lineLocation = mapView.getLayers().getBaseProjection().fromWgs84(location.getLongitude(), location.getLatitude());
    //arr_lat_long.add(new MapPos(lat, lng));
    arr_lat_long.add(lineLocation);
    Toast.makeText(getApplicationContext(), "Array list lat Lng" + arr_lat_long, 1000).show();
    if (arr_lat_long.size() > 2)
    {
        GeometryLayer geoLayer = new GeometryLayer(new EPSG4326());
        mapView.getLayers().addLayer(geoLayer);
        LineStyle lineStyle = LineStyle.builder().setLineJoinMode(LineStyle.ROUND_LINEJOIN).build();
        //Label label = new DefaultLabel("Line", "Here is a line");
        Line line = new Line(arr_lat_long, null, lineStyle, null);
        geoLayer.add(line);
    }
}
4

2 回答 2

2

问题是图层投影是 EPSG4326,但是您添加了 lineLocation 坐标,这些坐标转换为 baseProjection(基础图层的投影),通常是 EPSG3857。由于您的 geoLayer 已经是 EPSG4326,并且 GPS 坐标也是 EPSG4326 (WGS84),所以这就足够了:

MapPos lineLocation = new MapPos(location.getLongitude(), location.getLatitude());

另外:在这里,您正在为每个 GPS 位置坐标添加新图层、定义样式并添加新线(每延长 1 个点),这会每秒发生一次。所以你迟早会失去记忆。所以我建议重写你的代码:制作 geoLayer、lineStyle 和 line to fields。并在您的 app/mapview 生命周期内更新同一行对象:

line.setVertexList(arr_lat_long);
于 2014-05-20T10:56:08.790 回答
1

以下代码对我有用...

 @Override
            public void onLocationChanged(Location location)
            {
                Log.debug("GPS onLocationChanged " + location);
                if (locationCircle != null)
                {
                    MapPos lineLocation = mapView.getLayers().getBaseProjection().fromWgs84(location.getLongitude(), location.getLatitude());

                    //arr_lat_long.add(proj.fromWgs84(location.getLongitude(), location.getLatitude()));
                    //arr_lat_long.add(new MapPos(lat, lng));
                    arr_lat_long.add(lineLocation);


                    if (arr_lat_long.size() > 1)
                    {
                        Toast.makeText(getApplicationContext(), "Array list lat Lng" + arr_lat_long, 1000).show();

                        GeometryLayer geoLayer = new GeometryLayer(mapView.getComponents().layers.getBaseProjection());

                        mapView.getLayers().addLayer(geoLayer);
                        //LineStyle lineStyle = LineStyle.builder().setLineJoinMode(LineStyle.ROUND_LINEJOIN).build();  
                        StyleSet<LineStyle> lineStyleSet = new StyleSet<LineStyle>(LineStyle.builder().setWidth(0.05f).setColor(Color.BLUE).build());
                        Line line = new Line(arr_lat_long, null, lineStyleSet, null);
                        geoLayer.add(line);
                    }

                    }
于 2014-05-20T10:57:59.937 回答