app crashes if gps location is not in map

3971
5
Jump to solution
12-28-2012 08:55 AM
HamzaHaroon
Occasional Contributor
i try to enable gps and get this erro:

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

This error is because my current location is not in the map i am loading. how do i fix my code to be able to catch this error and display a message?

here is my code for displaying gps location

if (!self.mapView.gps.enable)
[self.mapView.gps start];
else
[self.mapView.gps stop];
0 Kudos
1 Solution

Accepted Solutions
HamzaHaroon
Occasional Contributor
what can i do to stop my app from crashing when i start the gps?

edit:

I got it. I used the CLLocationManager to create a CLLocationCoordinate2d object and then converted that into an agspoint with spatial reference wgs84.

then i just checked that point with the mapViews maxEnvelope

View solution in original post

0 Kudos
5 Replies
NimeshJarecha
Esri Regular Contributor
This error generally, pops up when GPS is not getting the signal. Do you see this error in simulator? or device?

Regards,
Nimesh
0 Kudos
HamzaHaroon
Occasional Contributor
on device. gps works fine if i load map that has my current location.
0 Kudos
NimeshJarecha
Esri Regular Contributor
So why you want to start the GPS when you are not/does not want to be at location? Or you want to start GPS and move/pan map to the current location? If yes, you should set autoPanMode property. like this..

if (!self.mapView.gps.enable) {
self.mapView.autoPanMode = AGSGPSAutoPanModeDefault;
[self.mapView.gps start];}
else {
[self.mapView.gps stop];}


Regards,
Nimesh
0 Kudos
HamzaHaroon
Occasional Contributor
i am able to load different maps in my app, and  have the gps function enabled by a button. I want it to display an error message if the current location of the device is not on the current loaded map
0 Kudos
HamzaHaroon
Occasional Contributor
what can i do to stop my app from crashing when i start the gps?

edit:

I got it. I used the CLLocationManager to create a CLLocationCoordinate2d object and then converted that into an agspoint with spatial reference wgs84.

then i just checked that point with the mapViews maxEnvelope
0 Kudos