@@ -17,33 +17,18 @@ + (BOOL)requiresMainQueueSetup {
1717 return YES ;
1818}
1919
20- - (instancetype )init {
21- self = [super init ];
22- if (self) {
23- // https://lbs.amap.com/api/ios-location-sdk/guide/create-project/ios-location-privacy
24- [AMapLocationManager updatePrivacyAgree: AMapPrivacyAgreeStatusDidAgree];
25- [AMapLocationManager updatePrivacyShow: AMapPrivacyShowStatusDidShow privacyInfo: AMapPrivacyInfoStatusDidContain];
26- _manager = [[AMapLocationManager alloc ] init ];
27- _manager.delegate = self;
28- // https://lbs.amap.com/api/ios-location-sdk/guide/get-location/singlelocation
29- // 由于苹果系统的首次定位结果为粗定位,其可能无法满足需要高精度定位的场景。
30- // 所以,高德提供了 kCLLocationAccuracyBest 参数,设置该参数可以获取到精度在 10m 左右的定位结果,但是相应的需要付出比较长的时间(10s左右),越高的精度需要持续定位时间越长。
31- // 推荐:kCLLocationAccuracyHundredMeters,一次还不错的定位,偏差在百米左右,超时时间设置在2s-3s左右即可。
32- [_manager setDesiredAccuracy: kCLLocationAccuracyHundredMeters ];
33- // 设置不允许系统暂停定位
34- [_manager setPausesLocationUpdatesAutomatically: NO ];
35-
36- [[AMapServices sharedServices ] setEnableHTTPS: YES ];
37-
38- _clManager = [CLLocationManager new ];
39- _locatingWithReGeocode = NO ;
40- _isStarted = NO ;
41- }
42- return self;
43- }
44-
45- RCT_EXPORT_METHOD (setApiKey: (NSString *)apiKey) {
20+ RCT_EXPORT_METHOD (setApiKey:(NSString *)apiKey) {
4621 [AMapServices sharedServices ].apiKey = apiKey;
22+ _manager = [[AMapLocationManager alloc ] init ];
23+ _manager.delegate = self;
24+ [AMapLocationManager updatePrivacyAgree: AMapPrivacyAgreeStatusDidAgree];
25+ [AMapLocationManager updatePrivacyShow: AMapPrivacyShowStatusDidShow privacyInfo: AMapPrivacyInfoStatusDidContain];
26+ [_manager setDesiredAccuracy: kCLLocationAccuracyHundredMeters ];
27+ [_manager setPausesLocationUpdatesAutomatically: NO ];
28+ [[AMapServices sharedServices ] setEnableHTTPS: YES ];
29+ _clManager = [CLLocationManager new ];
30+ _locatingWithReGeocode = NO ;
31+ _isStarted = NO ;
4732}
4833
4934// 定位超时时间,最低2s,默认设置为2s
@@ -314,4 +299,4 @@ - (void)amapLocationManager:(AMapLocationManager *)manager didFailWithError:(NSE
314299 }];
315300}
316301
317- @end
302+ @end
0 commit comments