Está en la página 1de 19

Curso de Iniciacin a la Programacin del iPhone SDK con Objective-C

Geolocalizacin

Moncada, a 9 de Julio de 2010

Introduccin

Muchas aplicaciones usan geolocalizacin En iPhone OS - Core Location Framework - MapKit Framework Hay que tener cuidad con el consumo de batera Triangulacin celular < Wifi < GPS

Core Location Framework

CLLocationManager Punto de entrada al servicio

Localizacin y precisin
CLLocation Objeto representa un punto y vector CLLocationManagerDelegate (Protocolo) didUpdateToLocation:fromLocation DidUpdateHeading didFailLoadWithError

CLLocation

Estructura

CLLocationCoordinate2D coordinate; CLLocationDistance altitude; CLLocationAccuracy horizontalAccuracy; CLLocationAccuracy verticalAccuracy; CLLocationDirection course; CLLocationSpeed speed; -(NSDAte*)timestamp; -distanceFromLocation:(CLLocation*)location

CLLocationManager

Estructura

CLLocation *location; Id <CLLocationManagerDelegate> delegate; CLLocationDistance distanceFilter; CLLocationAccuracy desiredAccuracy; -(void)startUpdatingLocation -(void)stopUpdatingLocation -(void)startUpdatingHeading -(void)stopUpdatingHeading

CLLocationManagerDelegate

Mtodo cuando cambia la localizacin - didUpdateToLocation:fromLocation; Mtodo cuando cambia la orientacin - didUpdateHeading; Mtodo para manejar los errores - didFailWithError;

MapKit Framework

API para mostrar mapas Clases para traducir coordenadas en direcciones (reversegeocoding) Soporta anotaciones sobre el mapa

MapKit Framework

Estructura MapKit Framework

Clases: MKMapView MKAnnotationView MKPlaceMark MKUserLocation MKReverseGeocoder Protocolos MKAnnotation Protocol MKMapViewDelegate

MKReverseGeocoderDelegate

MKMapView

Es la vista que se encarga de mostrar el mapa y las anotaciones Configuracin inicial del mapa Regin visible del mapa (punto central + span) Span: Cunto se ve del mapa Anotaciones de la vista Objeto que cumple protocolo MKAnnotation Mapa tiene NSArray objetos anotacin

MKMapView

Es la vista que se encarga de mostrar el mapa y las anotaciones Configuracin inicial del mapa Regin visible del mapa (punto central + span) Span: Cunto se ve del mapa Anotaciones de la vista Objeto que cumple protocolo MKAnnotation Mapa tiene NSArray objetos anotacin

MKMapView

Propiedades MKCoordinateRegion region; CLLocationCoordinate2D centerCoordinate; MKMapType mapType; NSArray *annotations; MKUserLocation userLocation; id <MKMapViewDelegate> delegate;

MKMapViewDelegate

Mtodos sobre la carga de estado: mapViewWillStartLoadingMap

mapViewDidFinishLoadingMap
mapViewDidFailLoadingMap:withError Mtodos sobre cambio de regin: regionWillChangeAnimated regionDidChangeAnimated Mtodos para anotaciones: viewForAnnotation didAddAnnotationViews annotationView:calloutAccessoryControlTapped

MKAnnotation

Es un protocolo, NO una clase El objeto que quiera cumplir el protocolo: @property CLLocationCoordinate2D coordinate; @property NSString *title; @property NSString *subtitle;

MKUserLocation

Caso especial de MKAnnotation Representa la localizacin del dispositivo Estructura: - @property BOOL updating (getter = isUpdating); - @property CLLocation *location; - @property NSString *title; - @property NSString *subtitle;

MKAnnotationView

- Vista para cada anotacin MKPinAnnotationView - Reusable (como UITableViewCell) - Callouts o 'bocadillos'

MKPlacemark

- Cumple protocolo MKAnnotation - Clase para almacenar una relacin entre coordenadas y direcciones legibles - initWithCoordinate:addressDictionary - Estructura Objetos NSString para almacenar calle, localidad, pas...

MKReverseGeocoder

Usa un servicio de red para convertir entre coordenadas y direccin legible (Google) Necesita conexin a internet Devuelve objeto MKPlacemark Protocolo MKReverseGeocoderDelegate - didFindPlacemark:(MKPlacemark *)placemark

Bibliografa

Core Location Framework Reference MapKit Framework Reference Location Awareness Programming Guide http://developer.apple.com

También podría gustarte