MapViewer Error

I am working with a Mapviewer control and on the most part it is working well but occasionally I get
“Resolving MapLocation timed out.” or “The operation couldn’t be completed. (kCLErrorDomain error 8.)”
error when it hits this code

MapViewer1.AddLocation(New MapLocation(l1.ToDouble,l2.ToDouble,MyTag))

I can’t seem to see a pattern and the values seem valid. Is there some sort of error check I could use to stop the app crashing?

Well for starters, create the location first and check to see if it’s nil.

The docs say:

If latitude or longitude passed is not valid, an InvalidArgumentException will occur.

Can you give an example of l1 and l2 when this doesn’t work?

Keep in mind that Latitudes are -90 to +90 and longitudes are -180 to 180.

1 Like

Is there a difference using maps in the simulator?

Actually when I check the roust of the data saved out it looks like this for Lat. and Long.

I think it must be a Simulator error?? Can you possibly get an error if you add the same location over and over?

You certainly can. Apple’s docs specifically say to not do that because it is very resource and battery intensive.

1 Like

I took my app into a location without reception and each screen that tried to load map locations crashed, even locations that where the Latitude and longitude were saved in the database.
Would it be the Mobilelocation control or the Mapviewer control? What would the best approach be for testing if an app has reception?

So… making a new Maplocation does what’s called a reverse-geocode, that is, it calls out to Apple’s servers to get the “actual” location for the location you passed. That’s definitely not going to work if you don’t have internet.

How do you stop it from looking if there is no connection?

Would the following prevent a location search until there is a signal?

If MyLocation.AuthorizationState = MobileLocation.AuthorizationStates.AuthorizedAppInUse Then
  ' we've got our requested authorization state, start getting LocationChanged events
  ' we don't have authorization yet, so ask for it
End If

What if I do a Socket.send request to get a file off our website and if that fails then we are out of mobile data range set a flag to not get Map data?

FileLoaderSocket1.Send(“GET”, “”)

That’ll probably tell you, but could give you a false negative if the file simply couldn’t be downloaded. Also, timeouts take the full duration to fail, so you should be prepared for that.

You can use the Reachability class in iOSKit to understand your network access level:

1 Like

Yes Greg you were correct, it sort of worked but if the user reacted too quickly the test was too slow so it only worked half the time.
I also tried to trap the error that occurred if they got through the check with the following but that didn’t work either

  locations.Add(New MapLocation(Mylat, Mylong,MyTag))
Catch e As InvalidArgumentException
End Try

Thanks Jason, I did look in IOSKit but was searching for the wrong words. On first tests it works great.

1 Like