Curso-Android-Desarrollo-de-Aplicaciones-Móviles
Curso-Android-Desarrollo-de-Aplicaciones-Móviles
Curso-Android-Desarrollo-de-Aplicaciones-Móviles
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
CURSO ANDROID<br />
69<br />
GeoPoint point;<br />
//El constructor recibe el punto don<strong>de</strong> se dibujará el marker<br />
public MyOverlay(GeoPoint point) {<br />
super();<br />
this.point = point;<br />
}<br />
@Overri<strong>de</strong><br />
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when)<br />
{<br />
super.draw(canvas, mapView, shadow);<br />
//se traduce el punto geolocalizado a un punto en la pantalla */<br />
Point scrnPoint = new Point();<br />
mapView.getProjection().toPixels(this.point, scrnPoint);<br />
//se construye un bitmap a partir <strong>de</strong> la imagen<br />
Bitmap marker = BitmapFactory.<strong>de</strong>co<strong>de</strong>Resource(getResources(),<br />
R.drawable.icon);<br />
// se dibuja la imagen <strong>de</strong>l marker<br />
canvas.drawBitmap(marker, scrnPoint.x - marker.getWidth() / 2,<br />
scrnPoint.y - marker.getHeight() / 2, null);<br />
return true;<br />
}<br />
}<br />
Para ir dibujando estos markers al principio y cada vez que haya una actualización <strong>de</strong> la ubicación, utilizaremos<br />
un método nuevo con la firma:<br />
protected void updateLocation(Location location)<br />
Obtenemos el MapView y <strong>de</strong> él un MapController:<br />
MapView mapView = (MapView) findViewById(R.id.mapview);<br />
MapController mapController = mapView.getController();<br />
Construimos un punto a partir <strong>de</strong> la latitud y longitud <strong>de</strong>l Location recibido:<br />
GeoPoint point = new GeoPoint((int) (location.getLatitu<strong>de</strong>() * 1E6), (int)<br />
(location.getLongitu<strong>de</strong>() * 1E6));