get location on iphone ONLY from the GPS - not the wifi network

扶醉桌前 提交于 2019-12-20 10:26:43

问题


i am creating an app that uses location-

everything works swimmingly except one thing-

when i come home my iphone connects to my local wifi network and instead of getting my location using the gps in the phone it tries to get it by figuring out where my wifi network is connected to- if i turn my wifi off it keeps an accurate location point-

as soon as my phone is connected to my wifi network it starts telling me my location is several km/miles from my actual point.

i would like my app NOT to use the wifi network to try get my location-

is there a way i can- a. tell if a location point has been derived from the GPS so i can ignore locations derived from the wifi network. b. stop location services jumping over to wifi for location


回答1:


Well I did some playing around

Found some apple documentation that says that [location verticalAccuracy] REQUIRES a device with gps.

So I stuck this code in (abridged) and based on the limited testing I have done, it appears to be doing what I want:

if (([location horizontalAccuracy] > 0) && ([location verticalAccuracy] > 0)){
     //report location here
}

Thanks all for your replies.




回答2:


Other than asking the user to turn off his Wifi, there's no documented way you can force the location manager to use GPS over Wifi. It might be possible with private API, but that would also get you rejected from the App Store.




回答3:


You can set cLLocationAccuracy.desiredAccuracy = kCLLocationAccuracyBest and see if that does it. It should try and limit to GPS use, however that isn't 100% guarenteed.




回答4:


The reason it uses WIFI at home is because there's no way it can have direct sight of the GPS satellites out in space - instead of not giving you any location data, it uses the next best available source.




回答5:


the inaccurate GPS coordinates are obtained by the iPhone not only via the Wi-Fi or mobile networks, but also the real-coordinates with accuracy level >100 metres.

What I use is to put the line: if (newLocation.horizontalAccuracy < 0 || newLocation.horizontalAccuracy > 50) return;

as the first line in the didUpdateToLocation, to filter out inaccurate coordinates.

The 'location age' i.e. NSTimeInterval locationAge=[locTimestamp timeIntervalSinceNow]; does NOT serve for me to get rid of cached coordinates.




回答6:


A-GPS = GPS + cell tower triangulation. There is no WI-FI positioning.



来源:https://stackoverflow.com/questions/3102423/get-location-on-iphone-only-from-the-gps-not-the-wifi-network

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!