-->

Core Location in iPhone Simulator 3.2 (iPad)

2019-01-25 15:09发布

问题:

So,

i'm trying to port my app to iPad. I'm using CoreLocation.

Apple says the iPad does have

Location:
Wi-Fi
Digital compass
Assisted GPS (Wi-Fi + 3G model)
Cellular (Wi-Fi + 3G model)

so it should be possible to get the position of my ipad (at least with 3g model) about 3km radius would be enought.

but it doesnt work in simulator (3.2 ipad) (running 3.1.3 in simulator simulates me cupertino).

is there a way to get the position in simulator (3.2 ipad) ? i live in germany and here the ipad isnt released yet, so i cannot test it on my device.

thanks!

edit

thats how i'm trying to get my connection

locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
locationManager.delegate = self;
[locationManager startUpdatingLocation];

and always on 3.2 locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error gets called. not on 3.1.3

error object looks like this:

Error Domain=kCLErrorDomain Code=0 "Operation could not be completed. (kCLErrorDomain error 0.)"

edit

so i handled it something like this:

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

    #ifdef TARGET_IPHONE_SIMULATOR
    // Cupertino
    CLLocation *simulatorLocation = [[CLLocation alloc] initWithLatitude:37.33168900 longitude:-122.03073100];
    [self locationManager:locationManager didUpdateToLocation:simulatorLocation fromLocation:nil];
    [simulatorLocation release];
    #else
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ErrorNotification"  object:NSLocalizedString(@"GPS-coordinates could not be detected",@"")];
    #endif

}

It is very messy but works.

edit2: try enabling your Airport, this could also solve the problem!!

回答1:

Yes, see this question which has several good answers to this.

EDIT - I eventually decided to write my own CLLocationManager simulator for testing on the iPhone simulator. It's located on github here if you want to use it.



回答2:

According to the iPhone Development Guide, the location in the simulator is fixed. Sorry!



回答3:

You might also wanna check out my FTLocationSimulator.

It reads a KML file generated by Google Earth to provide continuous location updates. It also updates the blue userLocation dot in a MKMapView with the simulated location updates.