簡體   English   中英

多次調用方法

[英]Call Method several times

我有一個應用程序,向用戶顯示他們的當前位置。 然而,我第一次調用該函數時,它顯示了錯誤的地址,但在第二次調用后,它通常會顯示正確的地址。

我想在顯示結果之前調用獲取地址的函數 5 次,從而提高每次調用的准確性。

- (IBAction)getCurrentLocation:(id)sender {
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;

[locationManager startUpdatingLocation];

有什么簡單的方法可以做到這一點嗎?

在此先感謝您,祝您一切順利

使用相同的數據多次調用反向地理編碼方法不會提高信息的准確性 - 只有接收更准確的定位才能做到這一點。

當核心位置有新的位置信息時,它會調用你的didUpdateLocations委托方法。 您應該在調用startUpdatingLocation立即調用此方法,但如果 GPS 接收器尚未初始化,則位置可能不太准確。

最近的位置是發送到委托方法的locations數組中的最后一個對象。 您可以檢查CLLocation[horizontalAccuracy][1]屬性以獲取位置不確定性圓的半徑(以米為單位)。 您可以使用此信息來決定是要向用戶顯示地址還是繼續等待更准確的位置。

但請注意,如果用戶在室內或 GPS 接收受阻,您可能永遠不會收到更准確的位置。

檢查位置管理器委托方法:

Responding to Location Events
– locationManager:didUpdateLocations:
– locationManager:didFailWithError:
– locationManager:didFinishDeferredUpdatesWithError:
– locationManager:didUpdateToLocation:fromLocation: Deprecated in iOS 6.0
Pausing Location Updates
– locationManagerDidPauseLocationUpdates:
– locationManagerDidResumeLocationUpdates:
Responding to Heading Events
– locationManager:didUpdateHeading:
– locationManagerShouldDisplayHeadingCalibration:
Responding to Region Events
– locationManager:didEnterRegion:
– locationManager:didExitRegion:
– locationManager:didDetermineState:forRegion:
– locationManager:monitoringDidFailForRegion:withError:
– locationManager:didStartMonitoringForRegion:
Responding to Ranging Events
– locationManager:didRangeBeacons:inRegion:
– locationManager:rangingBeaconsDidFailForRegion:withError:
Responding to Authorization Changes
– locationManager:didChangeAuthorizationStatus:

實現這些,然后一旦位置符合您的預期,您就可以更新您的用戶界面? 或者在一定次數后更新。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM