gps on simulator crashes

487
2
Jump to solution
11-05-2012 10:12 AM
PhilippFauser
New Contributor
Hi,

The following problem appears only in the iPhone simulator of xcode, on a real device it works!

I set up a mapView and display a map. This works absolutely fine, but when I try to start the gps with [self.mapView.gps start] the application crashes with the following error:

*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'


Has this something to do with different spacial references? The map is in GK4.


If someone has a little hint for, that would be very helpful!:)

Here is my code:

// static variables NSString* passauStreetMapUrl = @"http://www.geoportal.passau.de/ArcGIS/rest/services/STADTPLAN/MapServer"; NSString* passauAirMapUrl = @"http://www.geoportal.passau.de/ArcGIS/rest/services/LUFTBILD/MapServer"; NSString* passauPoiLayerUrl = @"http://www.geoportal.passau.de/ArcGIS/rest/services/APPDATEN/MapServer"; NSString* worldMapUrl = @"http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer";  - (void)viewDidLoad {     [super viewDidLoad];  // Do any additional setup after loading the view.              //set this class as the delegate for the mapview     self.mapView.layerDelegate = self;              //set wrap around vor the world map view     self.mapView.wrapAround = YES;          //create url     NSURL* urlPassauMap = [NSURL URLWithString: passauStreetMapUrl];     NSURL* urlPassauPoiLayer = [NSURL URLWithString: passauPoiLayerUrl];          //create tiled(PassauAirMap) and dynamic(PassauMap with layers) maps     self.layerPassauMap = [AGSDynamicMapServiceLayer dynamicMapServiceLayerWithURL: urlPassauMap];     self.layerPassauPoi = [AGSDynamicMapServiceLayer dynamicMapServiceLayerWithURL: urlPassauPoiLayer];          //add maps to view     UIView<AGSLayerView>* lyrView = [self.mapView addMapLayer:self.layerPassauMap withName:@"layerPassauMap"];     lyrView = [self.mapView addMapLayer:self.layerPassauPoi withName:@"layerPassauPoi"];          //set certain layers of the PassauMap to visible     self.layerPassauPoi.visibleLayers = [NSArray arrayWithObjects:[NSNumber numberWithInt:0], nil];          //better user experience on zooming and panning     lyrView.drawDuringPanning = YES;     lyrView.drawDuringZooming = YES; }


-(void) mapViewDidLoad:(AGSMapView*)mapView {     NSLog(@"INFO: mapViewDidLoad");   [self.mapView.gps start];           if (!mapView.gps.enabled) {   NSLog(@"The GPS is not enabled");  }  else if (mapView.gps.enabled) {   NSLog(@"The GPS is enabled");     }     }
0 Kudos
1 Solution

Accepted Solutions
RickJones
Occasional Contributor II
Could it be the simulator is using a default GPS location outside your map?

I've added the following code to the end of my ViewController:


#if TARGET_IPHONE_SIMULATOR

@interface CLLocationManager (Simulator)
@end

@implementation CLLocationManager (Simulator)

-(void)startUpdatingLocation {
    // City Hall:
    CLLocation *fakeLocation = [[CLLocation alloc] initWithLatitude:46.089796 longitude:-64.775348];
    // replace with your lat/long

    [self.delegate locationManager:self
               didUpdateToLocation:fakeLocation
                      fromLocation:fakeLocation];   
}

@end

#endif // TARGET_IPHONE_SIMULATOR

View solution in original post

0 Kudos
2 Replies
RickJones
Occasional Contributor II
Could it be the simulator is using a default GPS location outside your map?

I've added the following code to the end of my ViewController:


#if TARGET_IPHONE_SIMULATOR

@interface CLLocationManager (Simulator)
@end

@implementation CLLocationManager (Simulator)

-(void)startUpdatingLocation {
    // City Hall:
    CLLocation *fakeLocation = [[CLLocation alloc] initWithLatitude:46.089796 longitude:-64.775348];
    // replace with your lat/long

    [self.delegate locationManager:self
               didUpdateToLocation:fakeLocation
                      fromLocation:fakeLocation];   
}

@end

#endif // TARGET_IPHONE_SIMULATOR
0 Kudos
PhilippFauser
New Contributor
Thats it! 🙂

Thank you very much!
0 Kudos