Contenu connexe
Similaire à Map kit light
Similaire à Map kit light (20)
Plus de CocoaHeads France
Plus de CocoaHeads France (20)
Map kit light
- 23. + MapKit.framework
+ CoreLocation.framework
- 30. #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
- 36. @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;
- 38. - (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
- 43. #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)inKind
logged:(BOOL)inLogged;
@end
- 44. #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)inKind
logged:(BOOL)inLogged {
! self=[super init];
!
! if (self!=nil) {
! ! _coordinate=inCoordinate;
! ! _treeKind=inKind;
! ! _logged=inLogged;
- 45. #import "STSViewController.h"
#import "STSTreeAnnotation.h"
#import <CoreLocation/CoreLocation.h>
@interface STSViewController ()
{
IBOutlet MKMapView *_mapView;
}
- (void)delayedSaveVisibleMapRect;
@end
NSString * 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]
- 50. #import "STSViewController.h"
#import "STSTreeAnnotation.h"
#import <CoreLocation/CoreLocation.h>
@interface STSViewController ()
{
IBOutlet MKMapView *_mapView;
}
- (void)delayedSaveVisibleMapRect;
@end
NSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";
NSString * const STSTreeAnnotationIdentifier=@"STSTreeAnnotationIdentifier";
@implementation STSViewController
- (void)viewDidLoad
{…}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{…}
#pragma mark -
- (void)delayedSaveVisibleMapRect
- 57. - (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;
}
- 58. #import "STSViewController.h"
#import "STSTreeAnnotation.h"
#import "STSPinAnnotationView.h"
#import <CoreLocation/CoreLocation.h>
@interface STSViewController ()
{
IBOutlet MKMapView *_mapView;
}
- (void)delayedSaveVisibleMapRect;
@end
NSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";
NSString * const
STSTreeAnnotationSequoiadendronIdentifier=@"TreeAnnotationSequoiadendronIdentifier";
NSString * const
STSTreeAnnotationSempervirensIdentifier=@"TreeAnnotationSempervirensIdentifier";
NSString * const
STSTreeAnnotationMetasequoiaIdentifier=@"TreeAnnotationMetasequoiaIdentifier";
@implementation STSViewController
- (void)viewDidLoad
{…}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- 62. }
+ (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 {
- 63. #import "STSViewController.h"
#import "STSTreeAnnotation.h"
#import "STSTreeAnnotationView.h"
#import <CoreLocation/CoreLocation.h>
@interface STSViewController ()
{ MKPinAnnotationColorRed
IBOutlet MKMapView *_mapView;
}
- (void)delayedSaveVisibleMapRect;
@end
MKPinAnnotationColorPurple
NSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";
NSString * const STSTreeAnnotationViewIdentifier=@"TreeAnnotationViewIdentifier";
@implementation STSViewController
- (void)viewDidLoad
{…}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{…}
#pragma mark -
- 70. MKCircle MKPolyline MKPolygon
MKCircleView MKPolylineView MKPolygonView
- 74. <?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name><![CDATA[Val-d'Oise (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-d'Oise (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>
- 78. #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
- 79. #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;
! !
- 80. #import "STSViewController.h"
#import "STSTreeAnnotation.h"
#import "STSTreeAnnotationView.h"
#import "STSPolygonWrapper.h"
#import <CoreLocation/CoreLocation.h>
@interface STSViewController ()
{…}
- (void)delayedSaveVisibleMapRect;
@end
NSString * 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 */
- 89. #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
- 90. #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 {
- 91. #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
- 92. #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];
- 94. #import "STSViewController.h"
#import "STSPolygonWrapper.h"
#import <CoreLocation/CoreLocation.h>
@interface STSViewController ()
{
IBOutlet STSMapView *_mapView;
NSMutableArray *_overlays;
STSPolygonWrapper *_overlay;
}
- (void)delayedSaveVisibleMapRect;
@end
NSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";
@implementation STSViewController
- (void)viewDidLoad {
[super viewDidLoad];
/* Set Map Type to Terrain */
[_mapView setMapType:3];
- 97. Références
WWDC 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 Kit
KML
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/