在nutiteq地图上的折线onLocattionChanged

时间:2014-05-20 09:22:46

标签: android maps nutiteq

我一直在研究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);
    }
}

2 个答案:

答案 0 :(得分:3)

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

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

另外:在这里你要添加新图层,定义样式并为每个GPS位置坐标添加新线(每个下一个点长一点),每秒发生一次。所以你迟早会忘记内存。所以我建议重写你的代码:make geoLayer,lineStyle和line to fields。并使用以下内容在app / mapview生命周期内更新相同的行对象:

line.setVertexList(arr_lat_long);

答案 1 :(得分:2)

以下代码适用于我...

 @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);
                    }

                    }
相关问题