Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Movies Tab Not Showing Up on Apple Tv 2G polo3400 Apple TV and Home Theater 2 Jul 13, 2011 07:12 AM
iPhone World Clock has wrong time even though iPhone system time updated correctly medgirl2001 iPhone Tips, Help and Troubleshooting 19 Dec 15, 2010 08:00 AM
Battery icon is not showing 100% even after prolonged charging IndianSteveJobs MacBook Pro 2 Jul 26, 2010 09:30 AM
Can I activate a new Iphone now, even though my name is not on my Verizon account? blairh iPhone 5 Aug 8, 2008 02:38 PM
PC133 RAM read as PC100, even though Sys Bus is 133Mhz LucidX Macintosh Computers 3 Apr 21, 2004 06:43 PM


All times are GMT -5. The time now is 05:33 PM.

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

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