2016-08-15 82 views
5

我正在使用google位置API來獲取當前位置的正確信息。 I used this code in the App並獲得成功獲取所有附近地點的列表,但我怎樣才能從列表中識別出我確切的當前位置?Google當前在iOS中的位置準確度

我閱讀文檔,並發現我們基於可能性(0到1之間的值)從列表中獲得當前位置。

可能性越高意味着該地點是最佳匹配的概率越高。

但我目前的位置正在進入這個列表,但可能性值不高。

所以我有兩個問題:

1)我如何識別我的確切當前的位置?任何其他設置是否存在或有任何alert-net方式? (不使用地方選擇器)

2)如果我離開現在的地方,那麼我想要執行一些操作,那麼我怎樣才能得到我最近離開這個地方?像簽入/簽出?

+0

什麼v你有沒有收到可能性? – KENdi

+0

@KENdi - 我收到的值在0到1之間,但最大的值不是我當前的地方。那麼我怎樣才能得到準確的可能性值? – iPatel

回答

4

Google的API要求您初始化CLLocationManager。既然你已經有了位置管理器,你可以將你的類設置爲CLLocationManagerDelegate。這爲您提供了意味着你可以同時獲得一個確切的位置以及位置已改變

爲了得到一個確切的位置通知原生的iOS方法:

[self.locationManager requestLocation]; //Get the current location once (iOS 9 and above) 

要監視的位置:

[self.locationManager startUpdatingLocation] // Ask for the current location until you call stopUpdatingLocation 
// or 
[self.locationManager startMonitoringSignificantLocationChanges] // Tells you when your location has greatly changed 

然後您需要符合協議,該協議至少有2種方法:

- (void)locationManager:(CLLocationManager *)manager 
didUpdateLocations:(NSArray<CLLocation *> *)locations 
// Do anything that you need to do once you have a location update 

- (void)locationManager:(CLLocationManager *)manager 
    didFailWithError:(NSError *)error 
// Your location update failed, handle it 
+0

這不會幫助我,因爲,CLLocationManager不會給我我當前位置的準確信息。像地名,完整地址,評級等。 – iPatel

+0

您可以將iOS返回的位置傳遞給Google,以獲取有關位置的信息作爲反向地理編碼)。 iOS位置將爲您提供經度和緯度,您可以將其提供給'https://maps.googleapis.com/maps/api/geocode/json?latlng = xx.xxxxxx,-yy.yyyyyy&key = YOUR_API_KEY'。這裏有一個鏈接可以閱讀更多關於它的鏈接:https://developers.google.com/maps/documentation/geocoding/start 。否則,最大的可能是你最好的投注 –

+0

這不會給我像谷歌準確的位置信息地方給我提供準確的信息,由列表問題只有可能性是錯誤的,所以我無法得到正確的位置信息。 – iPatel