Drawing shapes in Android MapView independent of the zoom level

后端 未结 4 1643
南方客
南方客 2021-01-31 23:34

I need to draw shapes just like those you would create with custom maps on Google Maps, using Android\'s MapView.

In other words, if I draw a shape on t

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-31 23:58

    This maybe what you are looking for: Can "overlay" size be zoomed together with the google map on android?

    public class ImpactOverlay extends Overlay {
    
    private static int CIRCLERADIUS = 0;
    private GeoPoint geopoint;
    
    public ImpactOverlay(GeoPoint point, int myRadius) {
        geopoint = point;
        CIRCLERADIUS = myRadius;
    }
    
    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        // Transfrom geoposition to Point on canvas
        Projection projection = mapView.getProjection();
        Point point = new Point();
        projection.toPixels(geopoint, point);
    
        // the circle to mark the spot
        Paint circle = new Paint();
        circle.setColor(Color.BLACK);
        int myCircleRadius = metersToRadius(CIRCLERADIUS, mapView, (double)geopoint.getLatitudeE6()/1000000);
        canvas.drawCircle(point.x, point.y, myCircleRadius, circle);
    }
    
    public static int metersToRadius(float meters, MapView map, double latitude) {
        return (int) (map.getProjection().metersToEquatorPixels(meters) * (1/ Math.cos(Math.toRadians(latitude))));         
    }
    }
    

提交回复
热议问题