@@ -36,61 +36,64 @@ @implementation SVPlacemark
36
36
@synthesize formattedAddress, subThoroughfare, thoroughfare, subLocality, locality, subAdministrativeArea, administrativeArea, administrativeAreaCode, postalCode, country, ISOcountryCode, coordinate, location, region;
37
37
38
38
- (id )initWithDictionary : (NSDictionary *)result {
39
- self.formattedAddress = [result objectForKey: @" formatted_address" ];
40
39
41
- NSArray *addressComponents = [result objectForKey: @" address_components" ];
42
-
43
- [addressComponents enumerateObjectsUsingBlock: ^(NSDictionary *component, NSUInteger idx, BOOL *stopAddress) {
44
- NSArray *types = [component objectForKey: @" types" ];
45
-
46
- if ([types containsObject: @" street_number" ])
47
- self.subThoroughfare = [component objectForKey: @" long_name" ];
48
-
49
- if ([types containsObject: @" route" ])
50
- self.thoroughfare = [component objectForKey: @" long_name" ];
51
-
52
- if ([types containsObject: @" administrative_area_level_3" ] || [types containsObject: @" sublocality" ] || [types containsObject: @" neighborhood" ])
53
- self.subLocality = [component objectForKey: @" long_name" ];
40
+ if (self = [super init ]) {
41
+ self.formattedAddress = [result objectForKey: @" formatted_address" ];
54
42
55
- if ([types containsObject: @" locality" ])
56
- self.locality = [component objectForKey: @" long_name" ];
43
+ NSArray *addressComponents = [result objectForKey: @" address_components" ];
57
44
58
- if ([types containsObject: @" administrative_area_level_2" ])
59
- self.subAdministrativeArea = [component objectForKey: @" long_name" ];
45
+ [addressComponents enumerateObjectsUsingBlock: ^(NSDictionary *component, NSUInteger idx, BOOL *stopAddress) {
46
+ NSArray *types = [component objectForKey: @" types" ];
47
+
48
+ if ([types containsObject: @" street_number" ])
49
+ self.subThoroughfare = [component objectForKey: @" long_name" ];
50
+
51
+ if ([types containsObject: @" route" ])
52
+ self.thoroughfare = [component objectForKey: @" long_name" ];
53
+
54
+ if ([types containsObject: @" administrative_area_level_3" ] || [types containsObject: @" sublocality" ] || [types containsObject: @" neighborhood" ])
55
+ self.subLocality = [component objectForKey: @" long_name" ];
56
+
57
+ if ([types containsObject: @" locality" ])
58
+ self.locality = [component objectForKey: @" long_name" ];
59
+
60
+ if ([types containsObject: @" administrative_area_level_2" ])
61
+ self.subAdministrativeArea = [component objectForKey: @" long_name" ];
62
+
63
+ if ([types containsObject: @" administrative_area_level_1" ]) {
64
+ self.administrativeArea = [component objectForKey: @" long_name" ];
65
+ self.administrativeAreaCode = [component objectForKey: @" short_name" ];
66
+ }
67
+
68
+ if ([types containsObject: @" country" ]) {
69
+ self.country = [component objectForKey: @" long_name" ];
70
+ self.ISOcountryCode = [component objectForKey: @" short_name" ];
71
+ }
72
+
73
+ if ([types containsObject: @" postal_code" ])
74
+ self.postalCode = [component objectForKey: @" long_name" ];
75
+
76
+ }];
60
77
61
- if ([types containsObject: @" administrative_area_level_1" ]) {
62
- self.administrativeArea = [component objectForKey: @" long_name" ];
63
- self.administrativeAreaCode = [component objectForKey: @" short_name" ];
64
- }
78
+ NSDictionary *locationDict = [[result objectForKey: @" geometry" ] objectForKey: @" location" ];
79
+ NSDictionary *boundsDict = [[result objectForKey: @" geometry" ] objectForKey: @" bounds" ];
65
80
66
- if ([types containsObject :@" country " ]) {
67
- self. country = [component objectForKey: @" long_name " ];
68
- self.ISOcountryCode = [component objectForKey: @" short_name " ] ;
69
- }
81
+ CLLocationDegrees lat = [[locationDict objectForKey :@" lat " ] doubleValue ];
82
+ CLLocationDegrees lng = [[locationDict objectForKey: @" lng " ] doubleValue ];
83
+ self.coordinate = CLLocationCoordinate2DMake (lat, lng) ;
84
+ self. location = [[CLLocation alloc ] initWithLatitude: lat longitude: lng];
70
85
71
- if ([types containsObject: @" postal_code" ])
72
- self.postalCode = [component objectForKey: @" long_name" ];
73
-
74
- }];
75
-
76
- NSDictionary *locationDict = [[result objectForKey: @" geometry" ] objectForKey: @" location" ];
77
- NSDictionary *boundsDict = [[result objectForKey: @" geometry" ] objectForKey: @" bounds" ];
78
-
79
- CLLocationDegrees lat = [[locationDict objectForKey: @" lat" ] doubleValue ];
80
- CLLocationDegrees lng = [[locationDict objectForKey: @" lng" ] doubleValue ];
81
- self.coordinate = CLLocationCoordinate2DMake (lat, lng);
82
- self.location = [[CLLocation alloc ] initWithLatitude: lat longitude: lng];
83
-
84
- NSDictionary *northEastDict = [boundsDict objectForKey: @" northeast" ];
85
- NSDictionary *southWestDict = [boundsDict objectForKey: @" southwest" ];
86
- CLLocationDegrees northEastLatitude = [[northEastDict objectForKey: @" lat" ] doubleValue ];
87
- CLLocationDegrees southWestLatitude = [[southWestDict objectForKey: @" lat" ] doubleValue ];
88
- CLLocationDegrees latitudeDelta = fabs (northEastLatitude - southWestLatitude);
89
- CLLocationDegrees northEastLongitude = [[northEastDict objectForKey: @" lng" ] doubleValue ];
90
- CLLocationDegrees southWestLongitude = [[southWestDict objectForKey: @" lng" ] doubleValue ];
91
- CLLocationDegrees longitudeDelta = fabs (northEastLongitude - southWestLongitude);
92
- MKCoordinateSpan span = MKCoordinateSpanMake (latitudeDelta, longitudeDelta);
93
- self.region = MKCoordinateRegionMake (self.location .coordinate , span);
86
+ NSDictionary *northEastDict = [boundsDict objectForKey: @" northeast" ];
87
+ NSDictionary *southWestDict = [boundsDict objectForKey: @" southwest" ];
88
+ CLLocationDegrees northEastLatitude = [[northEastDict objectForKey: @" lat" ] doubleValue ];
89
+ CLLocationDegrees southWestLatitude = [[southWestDict objectForKey: @" lat" ] doubleValue ];
90
+ CLLocationDegrees latitudeDelta = fabs (northEastLatitude - southWestLatitude);
91
+ CLLocationDegrees northEastLongitude = [[northEastDict objectForKey: @" lng" ] doubleValue ];
92
+ CLLocationDegrees southWestLongitude = [[southWestDict objectForKey: @" lng" ] doubleValue ];
93
+ CLLocationDegrees longitudeDelta = fabs (northEastLongitude - southWestLongitude);
94
+ MKCoordinateSpan span = MKCoordinateSpanMake (latitudeDelta, longitudeDelta);
95
+ self.region = MKCoordinateRegionMake (self.location .coordinate , span);
96
+ }
94
97
95
98
return self;
96
99
}
0 commit comments