gpt4 book ai didi

android - 有没有办法在 osm map 上使用 osmdroid 折线绘制虚线?

转载 作者:行者123 更新时间:2023-11-29 18:30:12 26 4
gpt4 key购买 nike

我目前正在使用折线在 OSM map 上绘制 gpx 轨迹。

我想知道是否有办法使用 osmdroid 绘制虚线而不是实线?这是我的代码:

        Double firstLat, lastLat, firstLong, lastLong;
firstLat = lastLat = firstLong = lastLong = -100.0;


for (Track track : gpx.getTracks()) {

for (TrackSegment trackSegment : track.getTrackSegments()) {


Polyline line = new Polyline(mMap);
ArrayList<GeoPoint> trajet = new ArrayList<>();

for (TrackPoint trackPoint : trackSegment.getTrackPoints()) {
GeoPoint geoPoint = new GeoPoint(trackPoint.getLatitude(), trackPoint.getLongitude());
trajet.add(geoPoint);

if (firstLat == -100.0) { firstLat = trackPoint.getLatitude(); }

if (lastLat == -100.0) { lastLat = trackPoint.getLatitude(); }

if (firstLong == -100.0) { firstLong = trackPoint.getLongitude(); }

if (lastLong == -100.0) { lastLong = trackPoint.getLongitude(); }

if (trackPoint.getLatitude() < firstLat) { firstLat = trackPoint.getLatitude(); }

if (trackPoint.getLatitude() > lastLat) { lastLat = trackPoint.getLatitude(); }

if (trackPoint.getLongitude() < firstLong) { firstLong = trackPoint.getLongitude(); }

if (trackPoint.getLongitude() > lastLong) { lastLong = trackPoint.getLongitude(); }
}



line.setPoints(trajet);
line.setInfoWindow(null);
line.setColor(Color.rgb(0,191,255));

mMap.getOverlays().add(0, line);
mMap.invalidate();
}

谢谢!

编辑: 使用 line.getPaint().setPathEffect(new DashPathEffect(new float[]{10, 20}, 0)); 可以解决这个问题。

最佳答案

使用 getpaint().setPathEffect() 的代码:

Double firstLat, lastLat, firstLong, lastLong;
firstLat = lastLat = firstLong = lastLong = -100.0;


for (Track track : gpx.getTracks()) {

for (TrackSegment trackSegment : track.getTrackSegments()) {


Polyline line = new Polyline(mMap);
ArrayList<GeoPoint> trajet = new ArrayList<>();

for (TrackPoint trackPoint : trackSegment.getTrackPoints()) {
GeoPoint geoPoint = new GeoPoint(trackPoint.getLatitude(), trackPoint.getLongitude());
trajet.add(geoPoint);

if (firstLat == -100.0) { firstLat = trackPoint.getLatitude(); }

if (lastLat == -100.0) { lastLat = trackPoint.getLatitude(); }

if (firstLong == -100.0) { firstLong = trackPoint.getLongitude(); }

if (lastLong == -100.0) { lastLong = trackPoint.getLongitude(); }

if (trackPoint.getLatitude() < firstLat) { firstLat = trackPoint.getLatitude(); }

if (trackPoint.getLatitude() > lastLat) { lastLat = trackPoint.getLatitude(); }

if (trackPoint.getLongitude() < firstLong) { firstLong = trackPoint.getLongitude(); }

if (trackPoint.getLongitude() > lastLong) { lastLong = trackPoint.getLongitude(); }
}



line.setPoints(trajet);
line.setInfoWindow(null);
line.setColor(Color.rgb(0,191,255));
line.getPaint().setPathEffect(new DashPathEffect(new float[]{10, 20}, 0));


mMap.getOverlays().add(0, line);
mMap.invalidate();
}

关于android - 有没有办法在 osm map 上使用 osmdroid 折线绘制虚线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56685476/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com