Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tadelv

macrumors newbie
Original poster
Sep 20, 2008
12
0
Hello all!

i am developing a small app that uses the map kit and i would like to display the users location with the blue dot.

I use the corelocation services to obtain the current location and when the location is found, i present the map view. This means i know when corelocation has aquired a location that is accurate.

The problem is however, that the mapviews userlocation is nil -> how can this be? at least for a few seconds, then it sometimes displays and sometimes it doesnt.

does anyone have any idea, how to fix this? perhaps force a location update to mapview?

thanks!
 

kangaroo5383

macrumors newbie
Aug 10, 2009
2
0
i have the exact same problem... one way to get around it would be use the location manager delegate but I think that's very much an overkill. Can anyone help with this issue?
 

tcarcur

macrumors newbie
Jan 16, 2008
24
0
I had the same problem

My solution was to enable the user location dot after CL had found the location.

Code:
- (void)locationUpdate:(CLLocation *)location {
    [mapView setCenterCoordinate:location.coordinate];
    if ([mapView showsUserLocation] == NO) {
        [mapView setShowsUserLocation:YES];
    }
}

the "userLocation" property does not enable the blue dot.

if you enable setUserLocation before CL has a coordinate, the blue dot might not show.

Without setting any delegates, MKMapView still gets a location if the app is allowed for location updates. It gets its location updates for the blue dot from somewhere else.
 

tadelv

macrumors newbie
Original poster
Sep 20, 2008
12
0
Hello,

thank you for your replies.

To clear things up a little bit, i obviously was not specific enough.
I know that the CL has the updated location, i am handling it in another class, not in the viewcontroller.
So, when the location is updated, i present the map view. i add some annotations and set the showsUserLocation property to yes. The pins show, but the blue dot does not.
If i however go to the Maps.app first, update location there and return to my application, then the blue dot appears :)
i find this very confusing, has anyone contacted apple on this issue?
 

martijnthe

macrumors newbie
Aug 13, 2009
1
0
The Blue Dot - MKMapView's userLocation annotation

Hi all,
I just ran into the same problem you're describing.
I want to add my own annotation views as well, so I need to implement the mapView:viewForAnnotation: method on the MapView's delegate.
Also, I wanted to display the user's current position (the animated, blue dot).

The Blue Dot works by setting:
Code:
myMapView.showsUserLocation = YES

And by implementing the delegate method as follows:

Code:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
	MKAnnotationView* annotationView;
	
	if (annotation == mapView.userLocation)
	{
		// We can return nil to let the MapView handle the default annotation view (blue dot):
		// return nil;

		// Or instead, we can create our own blue dot and even configure it:

		annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"blueDot"];
		if (annotationView != nil)
		{
			annotationView.annotation = annotation;
		}
		else
		{
			annotationView = [[[NSClassFromString(@"MKUserLocationView") alloc] initWithAnnotation:annotation reuseIdentifier:@"blueDot"] autorelease];
			
			// Optionally configure the MKUserLocationView object here
			// Google MKUserLocationView for the options
			
		}
	}
	else
	{
		// The requested annotation view is for another annotation than the userLocation.
		// Let's return a normal pin:

		annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"regularPin"];
		
		if (annotationView != nil)
		{
			annotationView.annotation = annotation;
		}
		else
		{
			annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"regularPin"] autorelease];
		}
	}
	return annotationView;
}

Now both my pins appear, and the blue dot appears as soon as a location fix is found.
 

tadelv

macrumors newbie
Original poster
Sep 20, 2008
12
0
Hello!

i tried out your sample code - the blue dot appears! :)

however, as soon as i start moving the map around, i get the following error:
Code:
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <NSCFArray: 0x2fafc0> was mutated while being enumerated.'

It seems as if the dequeued "blueDot" is always nil... i'll look closer into it, but thanks! one step closer now :)
 

tadelv

macrumors newbie
Original poster
Sep 20, 2008
12
0
Ok, i managed to get the blueDot to appear everytime is show the mapView :)

Code:
- (void)resetUserLocation;

this one is undocumented however, but i think this is the way to go. maybe find another method that does something similar, because with this one, you get a approx. 1sec delay with the blue dot appearing.

anyways, thank you all for helping me out!
 

Pete8

macrumors newbie
Oct 8, 2009
1
0
Hi tadelv, Could you explain how you fixed the crash when zooming the map? I am having the same problem thanks!
 

dschiefer

macrumors newbie
Jan 11, 2010
3
0
UK
Same Problem

I have exactly the same issue, when I move around the map or zoom out for a short time, it crashes...has anyone found a solution for this?
 

dschiefer

macrumors newbie
Jan 11, 2010
3
0
UK
I have now found a solution myself, nothing was wrong with the code above, but I inserted an object that was already released, therefore causing the BAD_ACCESS error to occur and my app to crash. It only occurred when scrolling because the MKMapView was tracking my position and does so only every few seconds (think its 5?). therefore, after 5 seconds my app crashed...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.