-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBSKmlResult.m
111 lines (86 loc) · 2.43 KB
/
BSKmlResult.m
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
//
// Created by Björn Sållarp on 2010-03-13.
// NO Copyright 2010 MightyLittle Industries. NO rights reserved.
//
// Use this code any way you like. If you do like it, please
// link to my blog and/or write a friendly comment. Thank you!
//
// Read my blog @ http://blog.sallarp.com
//
/**
Object for storing placemark results from Googles geocoding API
**/
#import "BSKmlResult.h"
@implementation BSKmlResult
@synthesize address, accuracy, countryNameCode, countryName, subAdministrativeAreaName, localityName, addressComponents;
@synthesize viewportSouthWestLat, viewportSouthWestLon, viewportNorthEastLat, viewportNorthEastLon;
@synthesize boundsSouthWestLat, boundsSouthWestLon, boundsNorthEastLat, boundsNorthEastLon, latitude, longitude;
- (CLLocationCoordinate2D)coordinate
{
CLLocationCoordinate2D coordinate = {latitude, longitude};
return coordinate;
}
- (MKCoordinateSpan)coordinateSpan
{
// Calculate the difference between north and south to create a
// a span.
float latitudeDelta = viewportNorthEastLat - viewportSouthWestLat;
float longitudeDelta = viewportNorthEastLon - viewportSouthWestLon;
MKCoordinateSpan spn = {latitudeDelta, longitudeDelta};
return spn;
}
-(MKCoordinateRegion)coordinateRegion
{
MKCoordinateRegion region;
region.center = self.coordinate;
region.span = self.coordinateSpan;
return region;
}
-(NSArray*)findAddressComponent:(NSString*)typeName
{
NSMutableArray *matchingComponents = [[NSMutableArray alloc] init];
int components = [addressComponents count];
for(int i = 0; i < components; i++)
{
BSAddressComponent *component = [addressComponents objectAtIndex:i];
if(component.types != nil)
{
BOOL isMatch = NO;
int typesCount = [component.types count];
for(int j = 0; isMatch == NO && j < typesCount; j++)
{
NSString * type = [component.types objectAtIndex:j];
if([type isEqualToString:typeName])
{
[matchingComponents addObject:component];
isMatch = YES;
}
}
}
}
[matchingComponents autorelease];
return matchingComponents;
}
-(void)dealloc
{
if(address != nil) {
[address release];
}
if(countryNameCode != nil) {
[countryNameCode release];
}
if(countryName != nil) {
[countryName release];
}
if(subAdministrativeAreaName != nil) {
[subAdministrativeAreaName release];
}
if(localityName != nil) {
[localityName release];
}
if(addressComponents != nil){
[addressComponents release];
}
[super dealloc];
}
@end