我与OSMDroid工作,使Map离线在Android工作室。
这是我创建Polygon代码:
polygon = new Polygon();
polygon.setPoints(list_polygon);
polygon.setFillColor(Color.parseColor("#1D566E"));
polygon.setTitle(name_map);
polygon.getOutlinePaint().setColor(polygon.getFillPaint().getColor());
map.getOverlays().add(polygon);
这段代码用于创建行:
line = new Polyline();
line.setPoints(list_line);
line.setGeodesic(true);
line.setColor(Color.parseColor("#E33E5A"));
line.getOutlinePaint().setStrokeWidth(30f);
line.setWidth(15f);
line.getPaint().setStrokeCap(Paint.Cap.ROUND);
map.getOverlays().add(line);
这个代码是用来获取我的位置的
myLocation = new MyLocationNewOverlay(map);
myLocation.enableFollowLocation();
myLocation.setDirectionArrow(icTruk, icTruk);
myLocation.enableMyLocation();
myLocation.setDrawAccuracyEnabled(true);
map.getOverlays().add(myLocation);
我已经在osmdroid中创建了多边形和折线。但是现在我想读取那个多边形或折线,如果我的位置在那里的话?如何使它成为可能?
1条答案
按热度按时间v09wglhw1#
您可以执行以下操作以获取当前位置,然后检查它是否接近多段线。
检查location/GeoPoint是否在给定的多边形内是一个比较复杂的工作,因为唯一的集成方法是基于MotionEvent而不是GeoPoint,并且只在非常特定的场景中返回正确的值,请参阅此作为参考。但也有一些答案,可能会对您的需要有用,例如this one。
参考文献: