Permalink
Browse files

Changed from CLRegion to MKCoordinateRegion.

  • Loading branch information...
1 parent 1b48d3d commit 414a61a7a287d8c5a3d37ab8b62f80ba466a04f8 @xissburg xissburg committed Apr 12, 2012
Showing with 8 additions and 18 deletions.
  1. +5 −10 SVGeocoder/SVGeocoder.m
  2. +2 −2 SVGeocoder/SVPlacemark.h
  3. +1 −6 SVGeocoder/SVPlacemark.m
View
@@ -316,18 +316,16 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
CLLocationDegrees lng = [[coordinateDict valueForKey:@"lng"] floatValue];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(lat, lng);
- // Set the region radius as half the diagonal of the bounds
NSDictionary *northEastDict = [boundsDict objectForKey:@"northeast"];
NSDictionary *southWestDict = [boundsDict objectForKey:@"southwest"];
CLLocationDegrees northEastLatitude = [[northEastDict objectForKey:@"lat"] floatValue];
- CLLocationDegrees northEastLongitude = [[northEastDict objectForKey:@"lng"] floatValue];
- CLLocation *northEastLocation = [[CLLocation alloc] initWithLatitude:northEastLatitude longitude:northEastLongitude];
CLLocationDegrees southWestLatitude = [[southWestDict objectForKey:@"lat"] floatValue];
+ CLLocationDegrees latitudeDelta = fabs(northEastLatitude - southWestLatitude);
+ CLLocationDegrees northEastLongitude = [[northEastDict objectForKey:@"lng"] floatValue];
CLLocationDegrees southWestLongitude = [[southWestDict objectForKey:@"lng"] floatValue];
- CLLocation *southWestLocation = [[CLLocation alloc] initWithLatitude:southWestLatitude longitude:southWestLongitude];
- CLLocationDistance radius = [northEastLocation distanceFromLocation:southWestLocation]/2;
- [northEastLocation release];
- [southWestLocation release];
+ CLLocationDegrees longitudeDelta = fabs(northEastLongitude - southWestLongitude);
+ MKCoordinateSpan span = MKCoordinateSpanMake(latitudeDelta, longitudeDelta);
+ MKCoordinateRegion region = MKCoordinateRegionMake(coordinate, span);
NSMutableDictionary *formattedAddressDict = [[NSMutableDictionary alloc] init];
NSMutableArray *streetAddressComponents = [NSMutableArray arrayWithCapacity:2];
@@ -362,11 +360,8 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
if([streetAddressComponents count] > 0)
[formattedAddressDict setValue:[streetAddressComponents componentsJoinedByString:@" "] forKey:(NSString*)kABPersonAddressStreetKey];
- CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:coordinate radius:radius identifier:[placemarkDict objectForKey:@"formatted_address"]];
-
SVPlacemark *placemark = [[SVPlacemark alloc] initWithRegion:region addressDictionary:formattedAddressDict];
[formattedAddressDict release];
- [region release];
placemark.formattedAddress = [placemarkDict objectForKey:@"formatted_address"];
View
@@ -16,9 +16,9 @@
}
@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;
-@property (nonatomic, copy) CLRegion *region;
+@property (nonatomic, readwrite) MKCoordinateRegion region;
@property (nonatomic, retain) NSString * formattedAddress;
-- (id)initWithRegion:(CLRegion *)region addressDictionary:(NSDictionary *)addressDictionary;
+- (id)initWithRegion:(MKCoordinateRegion)region addressDictionary:(NSDictionary *)addressDictionary;
@end
View
@@ -30,7 +30,7 @@ - (id)initWithCoordinate:(CLLocationCoordinate2D)aCoordinate addressDictionary:(
return self;
}
-- (id)initWithRegion:(CLRegion *)region addressDictionary:(NSDictionary *)addressDictionary {
+- (id)initWithRegion:(MKCoordinateRegion)region addressDictionary:(NSDictionary *)addressDictionary {
if ((self = [super initWithCoordinate:region.center addressDictionary:addressDictionary])) {
self.coordinate = region.center;
@@ -40,11 +40,6 @@ - (id)initWithRegion:(CLRegion *)region addressDictionary:(NSDictionary *)addres
return self;
}
-- (CLRegion *)region
-{
- return _region;
-}
-
- (NSString*)description {
NSDictionary *coordDict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:self.coordinate.latitude], @"latitude", [NSNumber numberWithFloat:self.coordinate.longitude], @"longitude", nil];

0 comments on commit 414a61a

Please sign in to comment.