Drawing shapes in Android MapView independent of the zoom level

后端 未结 4 1565
南方客
南方客 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:53

    What you need is a list of lat/lon points for each shape you want to draw on the map. In the onDraw method, you need to iterate over that list (for each shape you want to draw), and do this:

    //---translate the GeoPoint to screen pixels---
      Point screenPts = new Point();
      mapView.getProjection().toPixels(p, screenPts);
    

    then draw the shape on the canvas. IIRC that works correctly regardless of zoom, because the mapView is aware of the zoom level, and gives you the appropriate pixel location for the lat/long pair at that zoom level.

提交回复
热议问题