20
20
};
21
21
22
22
typedef NSUInteger SVGeocoderState;
23
-
23
+ static NSString *googleMapsAPIKey;
24
24
25
25
@interface NSString (URLEncoding)
26
26
- (NSString *)encodedURLParameterString ;
@@ -42,9 +42,11 @@ @interface SVGeocoder ()
42
42
- (SVGeocoder*)initWithParameters : (NSMutableDictionary *)parameters completion : (SVGeocoderCompletionHandler)block ;
43
43
44
44
- (void )addParametersToRequest : (NSMutableDictionary *)parameters ;
45
+
45
46
- (void )finish ;
46
47
47
48
- (void )connection : (NSURLConnection *)connection didFailWithError : (NSError *)error ;
49
+
48
50
- (void )callCompletionBlockWithResponse : (id )response error : (NSError *)error ;
49
51
50
52
@end
@@ -102,7 +104,6 @@ - (SVGeocoder*)initWithAddress:(NSString*)address completion:(SVGeocoderCompleti
102
104
return [self initWithParameters: parameters completion: block];
103
105
}
104
106
105
-
106
107
- (SVGeocoder*)initWithAddress : (NSString *)address region : (CLRegion *)region completion : (SVGeocoderCompletionHandler)block {
107
108
MKCoordinateRegion coordinateRegion = MKCoordinateRegionMakeWithDistance (region.center , region.radius , region.radius );
108
109
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@@ -116,9 +117,9 @@ - (SVGeocoder*)initWithAddress:(NSString *)address region:(CLRegion *)region com
116
117
return [self initWithParameters: parameters completion: block];
117
118
}
118
119
119
- - (void )setGoogleMapsToken : (NSString *)token {
120
+ + (void )setGoogleMapsAPIKey : (NSString *)key {
120
121
121
- [ self addParametersToRequest: [@{ @" key" : token} mutableCopy] ];
122
+ googleMapsAPIKey = [ key copy ];
122
123
123
124
}
124
125
@@ -132,6 +133,11 @@ - (SVGeocoder*)initWithParameters:(NSMutableDictionary*)parameters completion:(S
132
133
133
134
[parameters setValue: @" true" forKey: @" sensor" ];
134
135
[parameters setValue: [NSLocale preferredLanguages ][0 ] forKey: @" language" ];
136
+
137
+ if (googleMapsAPIKey) {
138
+ [parameters setValue: googleMapsAPIKey forKey: @" key" ];
139
+ }
140
+
135
141
[self addParametersToRequest: parameters];
136
142
137
143
self.state = SVGeocoderStateReady;
0 commit comments