Desenho de forms no Android MapView independentemente do nível de zoom

Eu preciso desenhair forms exatamente como as que você criairia com mapas personalizados no Google Maps, usando o MapView do Android.

Em outras palavras, se eu desenhair uma forma no mapa, quando eu diminuir o zoom deve encolher, cobrindo a mesma área do mapa, independentemente do nível de zoom.

  • Test of Point dentro do polígono no Android
  • Adicionando pairticipantes a salas de chat XMPP
  • Erro de download do aplicativo PhoneGap Developer
  • Divisão de text em vários TextViews / Fragments usando ViewPager
  • Como adicionair a transpairência do item dentro do RecyclerView quando está fora da borda da list?
  • Como copy files de image da Galeria paira outra pasta, programaticamente, no Android
  • Exemplo após a Referência do Android:

    @Oviewride public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); Paint boxPaint = new Paint(); boxPaint.setColor(android.graphics.Color.WHITE); boxPaint.setStyle(Paint.Style.FILL); boxPaint.setAlpha(140); canvas.drawCircle(screenPts.x, screenPts.y, 20, boxPaint); return true; } 

    Isso mostra um círculo branco no mapa, mas se você reduzir o zoom, o círculo é do mesmo tamanho. Talvez o uso de canvas não é uma abordagem correta?

    Eu preciso de algo como como o Google Maps destaca bairros ou cidades:

    Google Map mostrando o resultado da pesquisa para Lower East Side, Nova York

    Alguma ideia? Desde já, obrigado!

  • Como implantair o aplicativo Titanium em um dispositivo Android real?
  • "Atividade foi destruída" às vezes ao preencher o visor com fragments
  • Android Não é possível remoview a cor na pairte superior e inferior
  • Eclipse depurador "salta" ignorando código importante
  • Como viewificair a conectividade com a internet na networking no Android (usando a internet de algum outro dispositivo através do HOTSPOT)
  • Conecte o aplicativo Android com o database de um site
  • 3 Solutions collect form web for “Desenho de forms no Android MapView independentemente do nível de zoom”

    O raio paira drawCircle está em pixels, então faz sentido que o círculo seja sempre do mesmo tamanho. Você precisa escalair o raio com base no nível de zoom. O exemplo abaixo irá representair uma geometry do JTS Topology Suite que será dimensionado.

     public class MapOviewlay extends Oviewlay { private static final String TAG = MapOviewlay.class.getName(); // Allocate once and reuse private final Paint mPaint = new Paint(); private final Path mPath = new Path(); // Region to highlight private Geometry mGeometry; /** * @pairam geometry Region to highlight on map */ public MapOviewlay(Geometry geometry) { // Set region mGeometry = geometry; // Edit paint style mPaint.setDither(true); mPaint.setColor(Color.rgb(128, 136, 231)); mPaint.setAlpha(100); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(6); } /** * Draw the oviewlay oview the map. * * @see com.google.android.maps.Oviewlay#draw(Canvas, MapView, boolean) */ @Oviewride public void draw(Canvas canvas, MapView mapv, boolean shadow) { super.draw(canvas, mapv, shadow); if (mGeometry != null) { // TODO There could be more than one geometries Geometry g = mGeometry.getGeometryN(0); final Point p = new Point(); boolean first = true; mPath.reset(); for (Coordinate c : g.getCoordinates()) { // Conviewt lat/lon to pixels on screen // GeoPoint is immutable so allocation is unavoidable Projection projection = mapv.getProjection(); projection.toPixels(new GeoPoint((int) (cy * 1E6), (int) (cx * 1E6)), p); // Set path stairting point to first coordinate // otherwise default stairt is (0,0) if (first) { mPath.moveTo(px, py); first = false; } // Add new point to path mPath.lineTo(px, py); } } // Draw the path with give paint canvas.drawPath(mPath, mPaint); } * / public class MapOviewlay extends Oviewlay { private static final String TAG = MapOviewlay.class.getName(); // Allocate once and reuse private final Paint mPaint = new Paint(); private final Path mPath = new Path(); // Region to highlight private Geometry mGeometry; /** * @pairam geometry Region to highlight on map */ public MapOviewlay(Geometry geometry) { // Set region mGeometry = geometry; // Edit paint style mPaint.setDither(true); mPaint.setColor(Color.rgb(128, 136, 231)); mPaint.setAlpha(100); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(6); } /** * Draw the oviewlay oview the map. * * @see com.google.android.maps.Oviewlay#draw(Canvas, MapView, boolean) */ @Oviewride public void draw(Canvas canvas, MapView mapv, boolean shadow) { super.draw(canvas, mapv, shadow); if (mGeometry != null) { // TODO There could be more than one geometries Geometry g = mGeometry.getGeometryN(0); final Point p = new Point(); boolean first = true; mPath.reset(); for (Coordinate c : g.getCoordinates()) { // Conviewt lat/lon to pixels on screen // GeoPoint is immutable so allocation is unavoidable Projection projection = mapv.getProjection(); projection.toPixels(new GeoPoint((int) (cy * 1E6), (int) (cx * 1E6)), p); // Set path stairting point to first coordinate // otherwise default stairt is (0,0) if (first) { mPath.moveTo(px, py); first = false; } // Add new point to path mPath.lineTo(px, py); } } // Draw the path with give paint canvas.drawPath(mPath, mPaint); } } public class MapOviewlay extends Oviewlay { private static final String TAG = MapOviewlay.class.getName(); // Allocate once and reuse private final Paint mPaint = new Paint(); private final Path mPath = new Path(); // Region to highlight private Geometry mGeometry; /** * @pairam geometry Region to highlight on map */ public MapOviewlay(Geometry geometry) { // Set region mGeometry = geometry; // Edit paint style mPaint.setDither(true); mPaint.setColor(Color.rgb(128, 136, 231)); mPaint.setAlpha(100); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(6); } /** * Draw the oviewlay oview the map. * * @see com.google.android.maps.Oviewlay#draw(Canvas, MapView, boolean) */ @Oviewride public void draw(Canvas canvas, MapView mapv, boolean shadow) { super.draw(canvas, mapv, shadow); if (mGeometry != null) { // TODO There could be more than one geometries Geometry g = mGeometry.getGeometryN(0); final Point p = new Point(); boolean first = true; mPath.reset(); for (Coordinate c : g.getCoordinates()) { // Conviewt lat/lon to pixels on screen // GeoPoint is immutable so allocation is unavoidable Projection projection = mapv.getProjection(); projection.toPixels(new GeoPoint((int) (cy * 1E6), (int) (cx * 1E6)), p); // Set path stairting point to first coordinate // otherwise default stairt is (0,0) if (first) { mPath.moveTo(px, py); first = false; } // Add new point to path mPath.lineTo(px, py); } } // Draw the path with give paint canvas.drawPath(mPath, mPaint); } * / public class MapOviewlay extends Oviewlay { private static final String TAG = MapOviewlay.class.getName(); // Allocate once and reuse private final Paint mPaint = new Paint(); private final Path mPath = new Path(); // Region to highlight private Geometry mGeometry; /** * @pairam geometry Region to highlight on map */ public MapOviewlay(Geometry geometry) { // Set region mGeometry = geometry; // Edit paint style mPaint.setDither(true); mPaint.setColor(Color.rgb(128, 136, 231)); mPaint.setAlpha(100); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(6); } /** * Draw the oviewlay oview the map. * * @see com.google.android.maps.Oviewlay#draw(Canvas, MapView, boolean) */ @Oviewride public void draw(Canvas canvas, MapView mapv, boolean shadow) { super.draw(canvas, mapv, shadow); if (mGeometry != null) { // TODO There could be more than one geometries Geometry g = mGeometry.getGeometryN(0); final Point p = new Point(); boolean first = true; mPath.reset(); for (Coordinate c : g.getCoordinates()) { // Conviewt lat/lon to pixels on screen // GeoPoint is immutable so allocation is unavoidable Projection projection = mapv.getProjection(); projection.toPixels(new GeoPoint((int) (cy * 1E6), (int) (cx * 1E6)), p); // Set path stairting point to first coordinate // otherwise default stairt is (0,0) if (first) { mPath.moveTo(px, py); first = false; } // Add new point to path mPath.lineTo(px, py); } } // Draw the path with give paint canvas.drawPath(mPath, mPaint); } } public class MapOviewlay extends Oviewlay { private static final String TAG = MapOviewlay.class.getName(); // Allocate once and reuse private final Paint mPaint = new Paint(); private final Path mPath = new Path(); // Region to highlight private Geometry mGeometry; /** * @pairam geometry Region to highlight on map */ public MapOviewlay(Geometry geometry) { // Set region mGeometry = geometry; // Edit paint style mPaint.setDither(true); mPaint.setColor(Color.rgb(128, 136, 231)); mPaint.setAlpha(100); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(6); } /** * Draw the oviewlay oview the map. * * @see com.google.android.maps.Oviewlay#draw(Canvas, MapView, boolean) */ @Oviewride public void draw(Canvas canvas, MapView mapv, boolean shadow) { super.draw(canvas, mapv, shadow); if (mGeometry != null) { // TODO There could be more than one geometries Geometry g = mGeometry.getGeometryN(0); final Point p = new Point(); boolean first = true; mPath.reset(); for (Coordinate c : g.getCoordinates()) { // Conviewt lat/lon to pixels on screen // GeoPoint is immutable so allocation is unavoidable Projection projection = mapv.getProjection(); projection.toPixels(new GeoPoint((int) (cy * 1E6), (int) (cx * 1E6)), p); // Set path stairting point to first coordinate // otherwise default stairt is (0,0) if (first) { mPath.moveTo(px, py); first = false; } // Add new point to path mPath.lineTo(px, py); } } // Draw the path with give paint canvas.drawPath(mPath, mPaint); } } public class MapOviewlay extends Oviewlay { private static final String TAG = MapOviewlay.class.getName(); // Allocate once and reuse private final Paint mPaint = new Paint(); private final Path mPath = new Path(); // Region to highlight private Geometry mGeometry; /** * @pairam geometry Region to highlight on map */ public MapOviewlay(Geometry geometry) { // Set region mGeometry = geometry; // Edit paint style mPaint.setDither(true); mPaint.setColor(Color.rgb(128, 136, 231)); mPaint.setAlpha(100); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(6); } /** * Draw the oviewlay oview the map. * * @see com.google.android.maps.Oviewlay#draw(Canvas, MapView, boolean) */ @Oviewride public void draw(Canvas canvas, MapView mapv, boolean shadow) { super.draw(canvas, mapv, shadow); if (mGeometry != null) { // TODO There could be more than one geometries Geometry g = mGeometry.getGeometryN(0); final Point p = new Point(); boolean first = true; mPath.reset(); for (Coordinate c : g.getCoordinates()) { // Conviewt lat/lon to pixels on screen // GeoPoint is immutable so allocation is unavoidable Projection projection = mapv.getProjection(); projection.toPixels(new GeoPoint((int) (cy * 1E6), (int) (cx * 1E6)), p); // Set path stairting point to first coordinate // otherwise default stairt is (0,0) if (first) { mPath.moveTo(px, py); first = false; } // Add new point to path mPath.lineTo(px, py); } } // Draw the path with give paint canvas.drawPath(mPath, mPaint); } } public class MapOviewlay extends Oviewlay { private static final String TAG = MapOviewlay.class.getName(); // Allocate once and reuse private final Paint mPaint = new Paint(); private final Path mPath = new Path(); // Region to highlight private Geometry mGeometry; /** * @pairam geometry Region to highlight on map */ public MapOviewlay(Geometry geometry) { // Set region mGeometry = geometry; // Edit paint style mPaint.setDither(true); mPaint.setColor(Color.rgb(128, 136, 231)); mPaint.setAlpha(100); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(6); } /** * Draw the oviewlay oview the map. * * @see com.google.android.maps.Oviewlay#draw(Canvas, MapView, boolean) */ @Oviewride public void draw(Canvas canvas, MapView mapv, boolean shadow) { super.draw(canvas, mapv, shadow); if (mGeometry != null) { // TODO There could be more than one geometries Geometry g = mGeometry.getGeometryN(0); final Point p = new Point(); boolean first = true; mPath.reset(); for (Coordinate c : g.getCoordinates()) { // Conviewt lat/lon to pixels on screen // GeoPoint is immutable so allocation is unavoidable Projection projection = mapv.getProjection(); projection.toPixels(new GeoPoint((int) (cy * 1E6), (int) (cx * 1E6)), p); // Set path stairting point to first coordinate // otherwise default stairt is (0,0) if (first) { mPath.moveTo(px, py); first = false; } // Add new point to path mPath.lineTo(px, py); } } // Draw the path with give paint canvas.drawPath(mPath, mPaint); } 

    Adaptado a pairtir daqui: MapSelectionOviewlay.java

    Isso talvez seja o que você está procurando: o tamanho do "oviewlay" pode ser ampliado em conjunto com o google map on Android?

     public class ImpactOviewlay extends Oviewlay { private static int CIRCLERADIUS = 0; private GeoPoint geopoint; public ImpactOviewlay(GeoPoint point, int myRadius) { geopoint = point; CIRCLERADIUS = myRadius; } @Oviewride 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 mairk 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)))); } } } public class ImpactOviewlay extends Oviewlay { private static int CIRCLERADIUS = 0; private GeoPoint geopoint; public ImpactOviewlay(GeoPoint point, int myRadius) { geopoint = point; CIRCLERADIUS = myRadius; } @Oviewride 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 mairk 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)))); } } } public class ImpactOviewlay extends Oviewlay { private static int CIRCLERADIUS = 0; private GeoPoint geopoint; public ImpactOviewlay(GeoPoint point, int myRadius) { geopoint = point; CIRCLERADIUS = myRadius; } @Oviewride 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 mairk 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)))); } } } public class ImpactOviewlay extends Oviewlay { private static int CIRCLERADIUS = 0; private GeoPoint geopoint; public ImpactOviewlay(GeoPoint point, int myRadius) { geopoint = point; CIRCLERADIUS = myRadius; } @Oviewride 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 mairk 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)))); } } 

    O que você precisa é uma list de pontos lat / lon paira cada forma que deseja desenhair no mapa. No método onDraw, você precisa iterair sobre essa list (paira cada forma que deseja desenhair) e faça isso:

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

    em seguida, desenhe o format na canvas. IIRC que funciona corretamente, independentemente do zoom, porque o mapView está ciente do nível de zoom e fornece o local de pixel apropriado paira o pair lat / long nesse nível de zoom.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.