MKMapView and setRegion: animated: do not update graphics

Hello! I am trying to use MKMapView without any Apple code samples, although there are several other of them of varying clarity. (I know, β€œRead the friendly manual.” I did it, but it's not 100% clear, so please carry me on that.)

Here is the situation. I have an MKMapView object in which I added a set of ten MKPinAnnotation objects. So far, so good. Everything is highlighted / released safely, and there seem to be no complaints from the Tools.

On initial display, I configured an MKCoordinateRegion object with a center point at our first output location and a (arbitrary) range of 0.2 x 0.2. Then I call:

[mapView setRegion:region animated:YES]; [mapView regionThatFits:region]; 

Wow! It worked out well.

Meanwhile ... I also have a segmented control that allows me to move around each contact point. Thus, when I scroll through the list, the map enlivens each new location of contacts with a new pair of calls to setRegion: animated: and regionThatFits: ... or at least that's the idea.

While the map "moves" to the new location of contacts, the map itself is not updated from below. Instead, I see my pin against a gray / blank card ... until I pushed the card in any direction, but not much. Then the map shows! (If I only move a short distance from the previous pin arrangement, I usually see which part of the map is already loaded.)

I suspect I'm doing something dumb here, but I couldn't understand that, at least, not from MapKit docs. Maybe I'm using the wrong calls? (Well, I need to set the area at least once, right? Moving around doesn't help, though.) I also tried using setCenterCoordinate: animated: - same problem.

I do not accept anything at this moment (no pun intended). Just trying to find my way.

Keys are welcome / appreciated!

UPDATE: calling setRegion: animated: and regionThatFits: for the first time, and then setCenterCoordinate: animated: while going through the list. no effect. An interesting conclusion: if I changed the animated value of NO in both cases, the map will be updated !!! Only when it is set to YES. (What's going on ?! Animated: broken? It can't be ... ???)

+4
source share
4 answers

It turns out that updating the map does not work when using SIMULATOR. When I try to setCenterCoordinate: animate: on the device, I get a map update under it.

Bottom line: I trusted the simulator to match the device in terms of map update behavior. Alas, I was wrong! Lesson learned. "Don't let this happen to you." :)

+6
source

You need to call the setRegion:animated: call in the context of the main thread. Just do something like:

 .... [self performSelectorOnMainThread:@selector(updateMyMap) withObject:nil waitUntilDone:NO]; } -(void) updateMyMap { [myMap setRegion:myRegion animated:YES]; } 

and it should work anyway (animated or not) with the updated map.

+2
source

Awful. The map is updated on my Mac even in the simulator. Maybe a network parameter (proxy server or something else) that will not allow the map widget to load tiles on the simulator?

0
source

Despite the fact that this is an old topic, I thought I would call my experience. It seems that the map animation does not work only on devices running iOS 3.1.x and a simulator running on 3.1.x. My iPod touch with 3.1.3 cannot scale if animation is turned on.

0
source

All Articles