开发者

CLLocationManager not updating location over Wifi

开发者 https://www.devze.com 2023-04-05 09:23 出处:网络
We have an app that is totally dependent on constant location updates and found that when the phone isn\'t getting gps, didUpdateToLocation isn\'t being called even if the device is connected to a wif

We have an app that is totally dependent on constant location updates and found that when the phone isn't getting gps, didUpdateToLocation isn't being called even if the device is connected to a wifi network. To further this test, I loaded the app on a 4th gen iPod Touch with the same results.

To clarify, the app workings perfectly on the iPhone 4 when GPS is available. We didn't notice the problem until the client tested it on his iPhone 4 in his office where he knows he doesn't get gps.

I thought that location manager was supposed to support wifi as a method to determine location, but this doesn't appear to be the case.

Here is my code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

if (locationManager=开发者_开发知识库=nil) {
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.distanceFilter = kCLDistanceFilterNone;

    NSLog(@"Accuracy best: %f distance filter none: %f", kCLLocationAccuracyBestForNavigation, kCLLocationAccuracyNearestTenMeters);
}
[locationManager startUpdatingLocation];

...

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{....

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{....

As far as I thought, there isn't anything special that you have to do to make locationManager work over wifi - and now I find out it doesn't work at all.

BTW- My phone device is an iPhone 4 running iOS 5 beta 7 and an ipod touch iOS 4.1.


I have discovered that didUpdateLocation is being called... once, when the app first opens. It makes me think that when you're dealing with wifi only, location manager is in startMonitoringSignificantLocationChanges mode only.


Try calling:

[self.locationManager startUpdatingLocation];

Possible you may need to configure your location manager parameters on self.locationManager as well.


It sounds as if your Wi-Fi Access Point is unknown. To make sure that it is not a coding error, in the simulator start Safari and see whether it finds your location. If it doesn't, the problem is your unknown Wi-Fi AP. The solution is to make your AP known to the outside wold. In order to do that, go to http://www.skyhookwireless.com and read the instructions. This site enables you to update your Wi-Fi Access Point information in the XPS system. Note: it took six weeks before I was hooked up, but it works now.

0

精彩评论

暂无评论...
验证码 换一张
取 消