Map kit light

4,415 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
4,415
On SlideShare
0
From Embeds
0
Number of Embeds
3,165
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Map kit light

  1. 1. MapKitCarnet de route
  2. 2. François PignonComptable au Ministère des Finances
  3. 3. Jeudi Confession Mode Thèmes iDVD activé
  4. 4. Infinite Loop - Cupertino
  5. 5. Yerba Buena Garden - San Francisco
  6. 6. Le Sequoia C’est quoi ?
  7. 7. Hauteur : 115,61 m Périmètre(1) : 47 m Poids : 2 100 t(1) Mesuré à 1,2 m du sol.
  8. 8. 4 033
  9. 9. ?
  10. 10. MapKit Framework
  11. 11. Afficher une carte
  12. 12. www.psdgraphics.com
  13. 13. MapKit Framework
  14. 14. MapKit Framework
  15. 15. + MapKit.framework+ CoreLocation.framework
  16. 16. Types de carte
  17. 17. MKMapTypeStandard MKMapTypeSatellite MKMapTypeHybrid
  18. 18. MKMapTypeStandard 3MKMapTypeSatelliteMKMapTypeHybrid
  19. 19. #import <UIKit/UIKit.h>#import <MapKit/MapKit.h>@interface STSViewController : UIViewController@end
  20. 20. #import "STSViewController.h"@interface STSViewController (){ IBOutlet MKMapView *_mapView;}@end@implementation STSViewController- (void)viewDidLoad { [super viewDidLoad]; [_mapView setMapType:3];}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES;}@end
  21. 21. Simulateur
  22. 22. Appareil
  23. 23. Simulateur#if TARGET_IPHONE_SIMULATOR [_mapView setMapType:MKMapTypeHybrid];#else [_mapView setMapType:3];#endif Appareil
  24. 24. Se souvenir de ladernière position
  25. 25. @property (nonatomic) MKCoordinateRegion region;- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated;@property (nonatomic) MKMapRect visibleMapRect;- (void)setVisibleMapRect:(MKMapRect)mapRect animated:(BOOL)animate;@protocol MKMapViewDelegate <NSObject>@optional- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated;
  26. 26. #import <UIKit/UIKit.h>#import <MapKit/MapKit.h>@interface STSViewController : UIViewController <MKMapViewDelegate>@end
  27. 27. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{…}#pragma mark -- (void)delayedSaveVisibleMapRect { MKMapRect tVisibleMapRect=_mapView.visibleMapRect; NSString *tString=[NSString stringWithFormat:@"%g|%g|%g|%g",tVisibleMapRect.origin.x, tVisibleMapRect.origin.y, tVisibleMapRect.size.width, tVisibleMapRect.size.height]; [[NSUserDefaults standardUserDefaults] setObject:tString forKey:STSLastVisibleMapRect];}#pragma mark - MKMapView delegate- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(delayedSaveVisibleMapRect) object:nil]; [self performSelector:@selector(delayedSaveVisibleMapRect) withObject:nil afterDelay:1.0];}@end
  28. 28. Indiquer unemplacement
  29. 29. Annotation
  30. 30. <MKAnnotation>MKPointAnnotation - le mal aimé
  31. 31. #import <MapKit/MapKit.h>#import "STSSharedConstants.h"@interface STSTreeAnnotation : NSObject <MKAnnotation>@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;@property (nonatomic, readonly) STSTreeKind treeKind;@property (nonatomic, readonly,getter=isTreeLogged) BOOL logged;+ (id)treeAnnotationWithCoordinate:(CLLocationCoordinate2D)inCoordinate treeKind:(STSTreeKind)inKind logged:(BOOL)inLogged;- (id)initWithCoordinate:(CLLocationCoordinate2D)inCoordinate treeKind:(STSTreeKind)inKindlogged:(BOOL)inLogged;@end
  32. 32. #import "STSTreeAnnotation.h"@interface STSTreeAnnotation (){! CLLocationCoordinate2D _coordinate;! STSTreeKind _treeKind;! BOOL _logged;}@end@implementation STSTreeAnnotation@synthesize coordinate=_coordinate,treeKind=_treeKind,logged=_logged;+ (id) treeAnnotationWithCoordinate:(CLLocationCoordinate2D)inCoordinate treeKind:(STSTreeKind)inKind logged:(BOOL)inLogged {! return [[[STSTreeAnnotation alloc] initWithCoordinate:inCoordinate treeKind:inKind logged:inLogged] autorelease];}- (id) initWithCoordinate:(CLLocationCoordinate2D)inCoordinate treeKind:(STSTreeKind)inKindlogged:(BOOL)inLogged {! self=[super init];!! if (self!=nil) {! ! _coordinate=inCoordinate;! ! _treeKind=inKind;! ! _logged=inLogged;
  33. 33. #import "STSViewController.h"#import "STSTreeAnnotation.h"#import <CoreLocation/CoreLocation.h>@interface STSViewController (){ IBOutlet MKMapView *_mapView;}- (void)delayedSaveVisibleMapRect;@endNSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";@implementation STSViewController- (void)viewDidLoad { [super viewDidLoad]; /* Set Map Type to Terrain */ [_mapView setMapType:3]; /* Restore (approximately) the visible map rect */ NSString *tString=[[NSUserDefaults standardUserDefaults]
  34. 34. MKAnnotationViewMKPinAnnotationView
  35. 35. MKPinAnnotationColorRed MKPinAnnotationColorGreenMKPinAnnotationColorPurple
  36. 36. MKPinAnnotationColorRedMKPinAnnotationColorPurple
  37. 37. #import "STSViewController.h"#import "STSTreeAnnotation.h"#import <CoreLocation/CoreLocation.h>@interface STSViewController (){ IBOutlet MKMapView *_mapView;}- (void)delayedSaveVisibleMapRect;@endNSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";NSString * const STSTreeAnnotationIdentifier=@"STSTreeAnnotationIdentifier";@implementation STSViewController- (void)viewDidLoad{…}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{…}#pragma mark -- (void)delayedSaveVisibleMapRect
  38. 38. Sequoia Sempervirens MetasequoiaSequoiadendron Giganteum Abattu
  39. 39. Sequoia Sempervirens Metasequoia Sequoiadendron Giganteum Abattu
  40. 40. CoreImage
  41. 41. #import <MapKit/MapKit.h>#import "STSSharedConstants.h"#import "STSTreeAnnotation.h"@interface STSPinAnnotationView : MKPinAnnotationView- (id)initWithAnnotation:(STSTreeAnnotation *) inTreeAnnotation reuseIdentifier:(NSString*)reuseIdentifier;@end
  42. 42. - (id)initWithAnnotation:(STSTreeAnnotation *)inTreeAnnotation reuseIdentifier:(NSString*)reuseIdentifier { self=[super initWithAnnotation:inTreeAnnotation reuseIdentifier:reuseIdentifier]; if (self!=nil) { if ([inTreeAnnotation isTreeLogged]==YES) { self.pinColor=MKPinAnnotationColorRed; } else { switch([inTreeAnnotation treeKind]) { case STSTreeKindSequoiadendronGiganteum: self.pinColor=MKPinAnnotationColorGreen; break; case STSTreeKindSequoiaSempervirens: self.pinColor=MKPinAnnotationColorPurple; break; case STSTreeKindMetasequoia: self.pinColor=MKPinAnnotationColorGreen; break; } } [super setImage:[self image]]; } return self;}
  43. 43. #import "STSViewController.h"#import "STSTreeAnnotation.h"#import "STSPinAnnotationView.h"#import <CoreLocation/CoreLocation.h>@interface STSViewController (){ IBOutlet MKMapView *_mapView;}- (void)delayedSaveVisibleMapRect;@endNSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";NSString * constSTSTreeAnnotationSequoiadendronIdentifier=@"TreeAnnotationSequoiadendronIdentifier";NSString * constSTSTreeAnnotationSempervirensIdentifier=@"TreeAnnotationSempervirensIdentifier";NSString * constSTSTreeAnnotationMetasequoiaIdentifier=@"TreeAnnotationMetasequoiaIdentifier";@implementation STSViewController- (void)viewDidLoad{…}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  44. 44. WTF?!#
  45. 45. }+ (UIImage *)imageForTreeKind:(STSTreeKind)treeKind logged:(BOOL)logged { UIImage *tImage=nil; if (logged==YES) { tImage=[UIImage imageNamed:@"loggedPin"]; } else { MKPinAnnotationColorRed switch(treeKind) { case STSTreeKindSequoiadendronGiganteum: tImage=[UIImage imageNamed:@"sequoiadendronPin"]; break; case STSTreeKindSequoiaSempervirens: tImage=[UIImage imageNamed:@"sempervirensPin"]; break; MKPinAnnotationColorPurple case STSTreeKindMetasequoia: tImage=[UIImage imageNamed:@"metasequoiaPin"]; break; } } return tImage;}#pragma mark -- (id)initWithAnnotation:(STSTreeAnnotation *)annotation reuseIdentifier:(NSString*)reuseIdentifier {
  46. 46. #import "STSViewController.h"#import "STSTreeAnnotation.h"#import "STSTreeAnnotationView.h"#import <CoreLocation/CoreLocation.h>@interface STSViewController (){ MKPinAnnotationColorRed IBOutlet MKMapView *_mapView;}- (void)delayedSaveVisibleMapRect;@end MKPinAnnotationColorPurpleNSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";NSString * const STSTreeAnnotationViewIdentifier=@"TreeAnnotationViewIdentifier";@implementation STSViewController- (void)viewDidLoad{…}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{…}#pragma mark -
  47. 47. Délimiter une région
  48. 48. Overlays
  49. 49. MKCircle MKPolyline MKPolygonMKCircleView MKPolylineView MKPolygonView
  50. 50. DonnéesGéographiques
  51. 51. www.gitesdegaule.fr/KaraMeLise/
  52. 52. <?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.2"><Document> <name><![CDATA[Val-dOise (95)]]></name> <Style id="gitesdegaule.fr"> <LineStyle> <color>cc2d3939</color> <width>3</width> </LineStyle> <PolyStyle> <color>804d4def</color> </PolyStyle> </Style> <Placemark id="val-doise"> <name><![CDATA[Val-dOise (95)]]></name> <styleUrl>#gitesdegaule.fr</styleUrl> <Polygon> <outerBoundaryIs> <LinearRing> <tessellate>1</tessellate> <coordinates> 2.20056187,48.90881128,250 </coordinates> </LinearRing> </outerBoundaryIs> </Polygon> </Placemark></Document></kml>
  53. 53. 2.20056187,48.90881128
  54. 54. > awk NR%2==0 input output
  55. 55. #import <MapKit/MapKit.h>@interface STSPolygonWrapper : NSObject <MKOverlay>@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;@property (nonatomic, readonly) MKMapRect boundingMapRect;@property (nonatomic, retain) MKPolygon *polygon;+ (STSPolygonWrapper *)polygonWrapperWithContentsOfURL:(NSURL *)inURL;- (id)initWithContentsOfURL:(NSURL *)inURL;- (BOOL)intersectsMapRect:(MKMapRect)inMapRect;@end
  56. 56. #import "STSPolygonWrapper.h"@interface STSPolygonWrapper (){! MKPolygon * _polygon;}@end@implementation STSPolygonWrapper@synthesize polygon=_polygon;+ (STSPolygonWrapper *)polygonWrapperWithContentsOfURL:(NSURL *)inURL {! STSPolygonWrapper *tPolygonWrapper=nil;!! if (inURL!=nil) tPolygonWrapper=[[STSPolygonWrapper alloc] initWithContentsOfURL:inURL];!! return [tPolygonWrapper autorelease];}- (id)initWithContentsOfURL:(NSURL *)inURL {! self=[super init];!! if (self!=nil) {! ! NSString *tRawCoordinates;! !
  57. 57. #import "STSViewController.h"#import "STSTreeAnnotation.h"#import "STSTreeAnnotationView.h"#import "STSPolygonWrapper.h"#import <CoreLocation/CoreLocation.h>@interface STSViewController (){…}- (void)delayedSaveVisibleMapRect;@endNSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";NSString * const STSTreeAnnotationViewIdentifier=@"TreeAnnotationViewIdentifier";@implementation STSViewController- (void)viewDidLoad { [super viewDidLoad]; /* Set Map Type to Terrain */ [_mapView setMapType:3]; /* Restore (approximately) the visible map rect */
  58. 58. Naviguer
  59. 59. Tap & Gestures
  60. 60. UIView ≠ UIView
  61. 61. #import <MapKit/MapKit.h>#define STSMAPVIEW_TRACKING_MODE_NORMAL! 0#define STSMAPVIEW_TRACKING_MODE_SPECIAL! 1@interface STSMapView : MKMapView{! NSInteger _trackingMode;! NSArray *_cachedOriginalRecognizers;}@property (nonatomic) NSInteger trackingMode;@end@protocol STSMapViewDelegate <MKMapViewDelegate>- (void) mapView:(STSMapView *)inMapView handleZoomInRequestAtPoint:(CGPoint)inPoint;- (void) mapView:(STSMapView *)inMapView handleZoomOutRequestAtPoint:(CGPoint)inPoint;@end
  62. 62. #import "STSMapView.h"@implementation STSMapView@synthesize trackingMode=_trackingMode;- (void) dealloc {! [_cachedOriginalRecognizers release];!! [super dealloc];}#pragma mark -- (void) setTrackingMode:(NSInteger)inMode {! if (_trackingMode!=inMode) {! ! if (inMode==STSMAPVIEW_TRACKING_MODE_NORMAL) {! ! ! self.zoomEnabled=YES; self.scrollEnabled=YES; if (_cachedOriginalRecognizers!=nil) {! ! ! ! self.gestureRecognizers=_cachedOriginalRecognizers;! ! ! !! ! ! ! [_cachedOriginalRecognizers release];! ! ! !! ! ! ! _cachedOriginalRecognizers=nil;! ! ! }! ! }! ! else {
  63. 63. #import <MapKit/MapKit.h>@interface STSPolygonWrapper : NSObject <MKOverlay>@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;@property (nonatomic, readonly) MKMapRect boundingMapRect;@property (nonatomic) BOOL contours;@property (nonatomic, retain) MKPolygon * polygon;@property (nonatomic, retain) NSString * label;+ (STSPolygonWrapper *)polygonWrapperWithContentsOfURL:(NSURL *)inURL label:(NSString*)inLabel;- (id)initWithContentsOfURL:(NSURL *) inURL label:(NSString *)inLabel;- (BOOL)containsPoint:(CLLocationCoordinate2D)inCoordinate;- (BOOL)intersectsMapRect:(MKMapRect)inMapRect;@end
  64. 64. #import "STSPolygonWrapper.h"@interface STSPolygonWrapper (){! MKPolygon * _polygon;! CGMutablePathRef _pathRef;! BOOL _contours; NSString * _label;}@end@implementation STSPolygonWrapper@synthesize polygon=_polygon,contours=_contours,label=_label;+ (STSPolygonWrapper *)polygonWrapperWithContentsOfURL:(NSURL *)inURL label:(NSString*)inLabel {! STSPolygonWrapper * tPolygonWrapper=nil;!! if (inURL!=nil) tPolygonWrapper=[[STSPolygonWrapper alloc] initWithContentsOfURL:inURL label:inLabel];!! return [tPolygonWrapper autorelease];}- (id)initWithContentsOfURL:(NSURL *)inURL label:(NSString *)inLabel {! self=[super init];
  65. 65. #import <UIKit/UIKit.h>#import <MapKit/MapKit.h>#import "STSMapView.h"@interface STSViewController : UIViewController <STSMapViewDelegate>@end
  66. 66. #import "STSViewController.h"#import "STSPolygonWrapper.h"#import <CoreLocation/CoreLocation.h>@interface STSViewController (){ IBOutlet STSMapView *_mapView; NSMutableArray *_overlays; STSPolygonWrapper *_overlay;}- (void)delayedSaveVisibleMapRect;@endNSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";@implementation STSViewController- (void)viewDidLoad { [super viewDidLoad]; /* Set Map Type to Terrain */ [_mapView setMapType:3];
  67. 67. Cluster
  68. 68. applidium.com/en/news/too_many_pins_on_your_map/
  69. 69. RéférencesWWDC sessions 2009 : Session 118 - Embedding Maps in iPhone Applications 2010 : Session 127 - Customizing Maps with Overlays 2011 : Session 111 - Visualizing Information Geographically with Map Kit 2012 : Session 300 - Getting Around With Map KitKML Régions : www.gitesdegaule.fr/KaraMeLise/ Déparetements : git.piprime.fr Git - php/pi-google-maps-api.git/ tree - pi-google-maps-api/res/france/regions/
  70. 70. RéférencesSample Code s.sudre.free.fr/Stuff/CocoaHeads/STSimplified-CocoaHeads.zip
  71. 71. www.sequoias.eu
  72. 72. QA &

×