views:

257

answers:

1

Does anyone know what triggers the blue marble animation. I know that it happens when the location gets updated but how do i trigger that event with whatever is in that property. I have an app that i would like to show the user's location when the map appears, but then clear the map of all annotations (including the user location)when the map disappears. This works fine. The problem comes in that when i try to go back into the map after removing the user location, the blue marble does not pop back in. Does anyone know how to set this animation going again?

thanks in advance.

+2  A: 

If you set your MKMapView to show the user's location by setting its property showsUserLocation to YES, then the map will automatically show the user's location unless his/her coordinates are outside the map. You can check this by inspecting the userLocationVisible property.

Now, if you remove the user's location (the property userLocation which is an annotation), then the map can not show the user' location even if you have showsUserLocation set to yes. Simply restore the userLocation again by updating it using the CoreLocation framework and it will appear automatically on the map again.

EDIT: To trigger the animation, update the user's location, setup again the region to be shown (may be the center and/or span have changed) and then call

[map setRegion:newRegion animated:YES];

If the region didn't change simply reuse it.

unforgiven
I tried this earlier by using the statement [locationManager startUpdatingLocation]. it updated the location, but the animating never popped in.
Makinitez21
Do you know what exactly triggers that event? the location updating obviously has something to do with it cause otherwise it would not do it the first time. But something else plays a part.
Makinitez21
I have updated the answer. This is what I do and it works for me.
unforgiven
thanks, I didn't quite do it that way, but that gave me an idea. I toggled the MapView.showsUserLocation and its updating now. thanks again
Makinitez21
Yes, the net effect is the same: either you set the region, forcing the map to refresh itself, or toggle the showsUserLocation property, again forcing the map to refresh. I always set the region because I have many different annotations to show besides the user's location.
unforgiven