@@ -55,6 +55,10 @@ @implementation RNGeocoder
55
55
}
56
56
57
57
RCT_EXPORT_METHOD (geocodeAddress:(NSString *)address
58
+ withSWLat:(CGFloat)swLat
59
+ withSWLng:(CGFloat)swLng
60
+ withNELat:(CGFloat)neLat
61
+ withNELng:(CGFloat)neLng
58
62
language:(NSString *)language
59
63
resolver:(RCTPromiseResolveBlock)resolve
60
64
rejecter:(RCTPromiseRejectBlock)reject)
@@ -68,6 +72,17 @@ @implementation RNGeocoder
68
72
}
69
73
70
74
CLGeocodeCompletionHandler handler = ^void (NSArray < CLPlacemark *> *placemarks, NSError *error) {
75
+ CLRegion* region;
76
+ if (swLat == 0 || swLng == 0 || neLat == 0 || neLng == 0 ){
77
+ region = nil ;
78
+ }else {
79
+ CLLocationCoordinate2D center = CLLocationCoordinate2DMake (swLat + (neLat-swLat) / 2 , swLng + (neLng-swLng) / 2 );
80
+ // Computing the radius based on lat delta, since 1 lat = 111 km no matter the location
81
+ float latDelta = neLat - swLat;
82
+ float radiusLat = (latDelta/2 );
83
+ float radius = radiusLat * 111000 ;
84
+ region = [[CLCircularRegion alloc ] initWithCenter: center radius: radius identifier: @" Search Radius" ];
85
+ }
71
86
if (error) {
72
87
if (placemarks.count == 0 ) {
73
88
return reject (@" NOT_FOUND" , @" geocodeAddress failed" , error);
@@ -78,7 +93,7 @@ @implementation RNGeocoder
78
93
};
79
94
80
95
if (@available (iOS 11.0 , *)) {
81
- [self .geocoder geocodeAddressString: address inRegion: nil preferredLocale: [NSLocale localeWithLocaleIdentifier: language] completionHandler: handler];
96
+ [self .geocoder geocodeAddressString: address inRegion: region preferredLocale: [NSLocale localeWithLocaleIdentifier: language] completionHandler: handler];
82
97
} else {
83
98
[self .geocoder geocodeAddressString: address completionHandler: handler];
84
99
}
0 commit comments