使用 Core Location 检测隧道
Detecting tunnels with Core Location
我正在使用 Core Location 进行转弯导航,并希望在隧道中显示 "GPS lost" 警报。
问题是以下两种情况在应用程序看来是一样的:
- 用户开车进入隧道。 GPS 更新停止,因为无法知道用户的位置。
- 用户停在了十字路口。 GPS 更新停止,因为用户不再移动。
我需要区分这两种情况。想法?
我曾尝试查看 horizontalAccuracy
属性,但有时更新会完全停止,因此没有新的 horizontalAccuracy
信息。
查看locationManager:didFailWithError:方法:
If the location service is unable to retrieve a location right away,
it reports a kCLErrorLocationUnknown error and keeps trying.
要确定第二种情况(用户停止),请使用 locationManagerDidPauseLocationUpdates: 方法:
When the location manager detects that the device’s location is not
changing, it can pause the delivery of updates in order to shut down
the appropriate hardware and save power. When it does this, it calls
this method to let your app know that this has happened.
通常情况下,将 CLLocationManager 设置为最佳导航精度并且没有距离过滤器,即使您停在十字路口,您也应该每秒更新一次位置。
如果你在运动协处理器(使用 CMMotionActivityManager
)说你还在开车时停止获取这些更新,那么你可以推断你在隧道(或地下停车场或 GPS 信号不好的地方) ).
顺便说一句,如果你设置了distanceFilter = 0
和desiredAccuracy = kCLLocationAccuracyBestForNavigation
和activityType = CLActivityTypeAutomotiveNavigation
等,当你在十字路口停车时GPS更新不应该停止
另一件需要注意的事情是,如果隧道有蜂窝网络覆盖,您仍然可以通过蜂窝三角测量获得位置更新,但准确性会降低。如果 CLLocation.horizontalAccuracy
从不到 50m 变为超过 300m,那么即使您仍在获取位置更新,您也已经失去 GPS/GLONASS 覆盖范围。
我正在使用 Core Location 进行转弯导航,并希望在隧道中显示 "GPS lost" 警报。
问题是以下两种情况在应用程序看来是一样的:
- 用户开车进入隧道。 GPS 更新停止,因为无法知道用户的位置。
- 用户停在了十字路口。 GPS 更新停止,因为用户不再移动。
我需要区分这两种情况。想法?
我曾尝试查看 horizontalAccuracy
属性,但有时更新会完全停止,因此没有新的 horizontalAccuracy
信息。
查看locationManager:didFailWithError:方法:
If the location service is unable to retrieve a location right away, it reports a kCLErrorLocationUnknown error and keeps trying.
要确定第二种情况(用户停止),请使用 locationManagerDidPauseLocationUpdates: 方法:
When the location manager detects that the device’s location is not changing, it can pause the delivery of updates in order to shut down the appropriate hardware and save power. When it does this, it calls this method to let your app know that this has happened.
通常情况下,将 CLLocationManager 设置为最佳导航精度并且没有距离过滤器,即使您停在十字路口,您也应该每秒更新一次位置。
如果你在运动协处理器(使用 CMMotionActivityManager
)说你还在开车时停止获取这些更新,那么你可以推断你在隧道(或地下停车场或 GPS 信号不好的地方) ).
顺便说一句,如果你设置了distanceFilter = 0
和desiredAccuracy = kCLLocationAccuracyBestForNavigation
和activityType = CLActivityTypeAutomotiveNavigation
等,当你在十字路口停车时GPS更新不应该停止
另一件需要注意的事情是,如果隧道有蜂窝网络覆盖,您仍然可以通过蜂窝三角测量获得位置更新,但准确性会降低。如果 CLLocation.horizontalAccuracy
从不到 50m 变为超过 300m,那么即使您仍在获取位置更新,您也已经失去 GPS/GLONASS 覆盖范围。