2016-08-15 84 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