un atlas en la palma de la mano

Post on 13-Jun-2015

1.347 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

Codelab sobre Google Maps impartida en Google DevFest 2012 de Barcelona.

TRANSCRIPT

Un atlas en la palma de la manoIncluyendo mapas en Android por J. M. Pereira

Presentación

http://www.ingens-developments.com/

http://androcode.es/

Jose Manuel Pereira (@JMPergar) Ismael Reyes (@kix2902)

Contenido Google Maps en apps Android

android-mapviewballoons Polaris

OpenStreetMap en Android OSMDroid y OSMDroidBonusPack MapsForge

Nuestra app conGoogle Maps Incluir la API de Google en el proyecto. Incluir com.google.android.maps.MapView en nuestro layout.

Configurar Manifest. Indicar el uso de la librería.

Indicar permiso de acceso a internet.

Extender de MapActivity.

<com.google.android.maps.MapView android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:apiKey="@string/googlemap_key" android:clickable="true" />

<uses-library android:name="com.google.android.maps" />

<uses-permission android:name="android.permission.INTERNET" />

Obteniendo el Maps API key Obtenemos la firma de desarrollo

Windows Vista y Windows 7 c:\users\<user>\.android\debug.keystore

Windows XP c:\Documents and Settings\<user>\.android\debug.keystore

OSX y Linux ~/.android/debug.keystore

Obtenemos la huella MD5 de la firma con keytool

Registrar la firma https://developers.google.com/android/maps-api-signup

keytool –list –alias androiddebugkey –keystore debug.keystore –storepass android –keypass androidCertificate fingerprint (MD5): 94:1E:43:49:87:73:BB:E6:A6:88:D7:20:F1:8E:B5:98

NOTA: Es necesario tener instalado el JDK. Con el JDK7 añadir el parámetro –v.

Controlando nuestros mapas MapView (findViewById)

setBuiltInZoomControls(boolean) setSatellite(boolean)

MapController (MapView.getController) setCenter(GeoPoint) setZoom(int) animateTo(GeoPoint)

Controlando nuestros mapas GeoPoint

Representa un punto en el mapa Indicado en microgrados enteros Para convertir:

Para obtener la geolocalización: http://

tools.freeside.sk/geolocator/geolocator.html https://maps.google.es/

GeoPoint centro = new GeoPoint((int)(37.380882 * 1E6), (int)(-5.986958 * 1E6));

Poblando nuestros mapas Capas o Overlays

MapView.getOverlays() MyLocationOverlay

enableMyLocation() enableCompass() Activarlos en onResume() y desactivarlos

en onPause. MapView.postInvalidate() para

actualizar

Polaris de Cyrill Mottier Proyecto Librería

https://github.com/cyrilmottier/Polaris ¿Qué nos ofrece?

Burbujas de información Double tap on map Double tap on map balloon Una manera fácil de hacerlo

Polaris de Cyrill Mottier Creamos y enlazamos el proyecto

URL de descarga del proyecto Incorporamos la View

com.cyrilmottier.polaris.PolarisMapView Extends MapActivity mPolarisMapView.onStart() y

mPolarisMapView.onStop()

Poblando Polaris PolarisMapView posee métodos similares a MapView y

MapController. Class Annotation (new Annotation(GeoPoint, String,

String) Title Snippet Marker (Annotation.setMarker(Drawable))

MapViewUtils.boundMarkerCenterBottom mPolarisMapView.setAnnotations(List<Annotation>, int) No usar getOverlays(), addOverlay(), removeOverlay() y

metodos similares, ya que afectan al ciclo de vida de Polaris.

Poblando Polaris implements OnAnnotationSelectionChangedListener mPolarisMapView.setOnAnnotationSelectionChangedListener(thi

s); @Override

onAnnotationClicked onAnnotationSelected onAnnotationDeselected

onAnnotationSelected Añadiendo imagen al globo de información

if (!TextUtils.isEmpty(annotation.getSnippet())) { calloutView.setLeftAccessoryView(getLayoutInflater().inflate(R.layout.accessory, calloutView, false));} else { calloutView.setLeftAccessoryView(null);}

<?xml version="1.0" encoding="utf-8"?><ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" />

Más Polaris setUserTrackingButtonEnabled(true)

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission

android:name="android.permission.ACCESS_COARSE_LOCATION" />

Post ofcial http://android.cyrilmottier.com/?p=824

OpenStreetMap en Android No existe librería oficial Gratis pero con limitaciones Mapas Offline OSMDroid y OSMDroidBonusPack

Bajo rendimiento http://androcode.es/tag/osmdroid/

MapsForge Mapas vectoriales y themes Rendimiento muy bueno Poco madura http://www.ingens-networks.com/blog/?tag=/MapsForg

e

¡GRACIAS A TODOS!

jm.pereira.g@gmail.com @JMPergarismael.kix2902@gmail.com @kix2902

top related