Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 5, 2009, 06:14 AM   #1
tadelv
macrumors newbie
 
Join Date: Sep 2008
MKMapView not showing userLocation, even though the location is updated

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!
tadelv is offline   0 Reply With Quote
Old Aug 10, 2009, 01:37 PM   #2
kangaroo5383
macrumors newbie
 
Join Date: Aug 2009
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?
kangaroo5383 is offline   0 Reply With Quote
Old Aug 10, 2009, 07:06 PM   #3
tcarcur
macrumors newbie
 
Join Date: Jan 2008
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.
tcarcur is offline   0 Reply With Quote
Old Aug 11, 2009, 02:38 AM   #4
tadelv
Thread Starter
macrumors newbie
 
Join Date: Sep 2008
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?
tadelv is offline   0 Reply With Quote
Old Aug 13, 2009, 08:18 PM   #5
martijnthe
macrumors newbie
 
Join Date: Aug 2009
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.
martijnthe is offline   0 Reply With Quote
Old Aug 14, 2009, 09:52 AM   #6
tadelv
Thread Starter
macrumors newbie
 
Join Date: Sep 2008
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 is offline   0 Reply With Quote
Old Aug 14, 2009, 11:37 AM   #7
tadelv
Thread Starter
macrumors newbie
 
Join Date: Sep 2008
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!
tadelv is offline   0 Reply With Quote
Old Oct 8, 2009, 05:19 PM   #8
Pete8
macrumors newbie
 
Join Date: Oct 2009
Hi tadelv, Could you explain how you fixed the crash when zooming the map? I am having the same problem thanks!
Pete8 is offline   0 Reply With Quote
Old Jan 11, 2010, 09:28 AM   #9
dschiefer
macrumors newbie
 
Join Date: Jan 2010
Location: 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 is offline   0 Reply With Quote
Old Jan 11, 2010, 03:30 PM   #10
dschiefer
macrumors newbie
 
Join Date: Jan 2010
Location: 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...
__________________
MacBook Pro 2.53GHZ Late 2009 Model, iMac 2007 Model, iPhone 3GS 16GB Black
dschiefer is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Why Location Services Icon Keep Showing On [ 7.1 ] ??? icloud87 iOS 7 1 Mar 11, 2014 12:56 PM
iPad World clock showing time of your location? sananda iOS 7 5 Nov 26, 2013 09:38 AM
Weather app showing wrong location as local? jigzaw iOS 6 2 Oct 28, 2012 08:23 PM
Location Services has been randomly showing up AlphaVictor87 iOS 6 16 Oct 4, 2012 12:30 PM
Zui widget not showing location and weather ? Dropkangoo Jailbreaks and iOS Hacks 6 Jul 3, 2012 11:29 AM

Forum Jump

All times are GMT -5. The time now is 11:58 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC