forked from 0x0c/CLLocationManager-blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.m
More file actions
126 lines (104 loc) · 3.03 KB
/
ViewController.m
File metadata and controls
126 lines (104 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
// ViewController.m
// CLLocationManager+blocks
//
// Created by 暁 松田 on 12/02/13.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "ViewController.h"
#import "CLLocationManager+blocks.h"
#import "MTAnnotation.h"
@implementation ViewController
@synthesize mapView = mapView_;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
mapView_.delegate = self;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
manager_ = nil;
mapView_ = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)dealloc
{
[manager_ release], manager_ = nil;
[mapView_ release], mapView_ = nil;
[super dealloc];
}
#pragma mark MKMapViewDelegate
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if (annotation == mapView.userLocation) {
return nil;
}
static NSString *reuseIdentifier = @"pin";
MKPinAnnotationView *pin = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseIdentifier];
if (!pin) {
pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIdentifier] autorelease];
}
pin.pinColor = MKPinAnnotationColorRed;
pin.canShowCallout = YES;
pin.animatesDrop = YES;
return pin;
}
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
NSLog(@"show");
}
#pragma mark -
- (IBAction)getLocation:(id)sender
{
manager_ = [[CLLocationManager alloc] initWithUpdateBlock:^(CLLocationManager *manager, CLLocation *newLocation, CLLocation *oldLocation, BOOL *stop){
MKCoordinateRegion cr = mapView_.region;
cr.center = newLocation.coordinate;
cr.span.latitudeDelta = 0.4;
cr.span.longitudeDelta = 0.4;
[mapView_ setRegion:cr animated:YES];
[mapView_ removeAnnotations:mapView_.annotations];
MTAnnotation *annotation = [[MTAnnotation alloc] initWithCoordinate:newLocation.coordinate];
annotation.title = @"title";
annotation.subtitle = @"subtitle";
[mapView_ addAnnotation:annotation];
[mapView_ selectAnnotation:annotation animated:YES];
[annotation release];
NSLog(@"update");
} errorBlock:^(NSError *error){
NSLog(@"%@",error);
}];
manager_.distanceFilter = 1.0;
manager_.desiredAccuracy = kCLLocationAccuracyBest;
[manager_ startUpdatingLocation];
}
@end