0

I set the mapView's showUserLocation property to YES, and it does nothing. I was able to use a CLLocationManager to center the map on the user's current location, but there's no pin/dot on the screen. How can I put a pin on the map for the exact location of the user?

Tim
  • 4,295
  • 9
  • 37
  • 49
  • Are you doing anything with annotations on the map view? It's possible you're not allowing the blue dot annotation to be displayed, I've made that mistake before. – Paul Tiarks Aug 04 '11 at 17:03
  • I was but I commented it out and it's still not showing any marker for the current location. – Tim Aug 04 '11 at 17:17
  • Is this on the simulator or device? On the simulator, the "user location" using showsUserLocation will be Cupertino, CA but the CLLocationManager will return the real location regardless. –  Aug 04 '11 at 17:18
  • That's what I thought it was at first too, but I tried it on a device and it does the same thing. Also, when I zoom all the way out it doesn't show any blue dot in California either. – Tim Aug 04 '11 at 17:24
  • Is the property set in code or IB? Make sure the IBOutlet is hooked up. If you have implemented viewForAnnotation, try commenting it out or post that code. If you implement all the delegate methods listed under "Tracking the User Location" in the MKMapViewDelegate protocol reference (eg. didUpdateUserLocation), do any of them get called (make sure the map view's delegate is set)? –  Aug 04 '11 at 17:35
  • I figured it out (kinda). Since it was coming in from a Xib, I just checked the box in interface builder that says "Shows User Location". No idea I wasn't able to do it programmatically, but it works now. – Tim Aug 04 '11 at 19:20
  • Sounds like IBOutlet is not hooked up (assuming the code that sets showsUserLocation to YES is correct). –  Aug 04 '11 at 19:39
  • No, it's hooked up, so I have no clue. – Tim Aug 04 '11 at 20:22

2 Answers2

0

IN Nib name you can set showuserlocation to mark for Mapview.

K.D
  • 516
  • 3
  • 14
0

This has messed me up several times but its an easy fix

The problem is that your code is:

 [self.mapView showUserLocation:YES];

Should be:

 [self.mapView setShowsUserLocation:YES]

Also make sure you have set the delegate as well

rich
  • 2,136
  • 19
  • 23
  • I was doing self.mapView.showUserLocation:YES anyway, which would be equivalent to the second option you gave. Appreciate the answer anyway. – Tim Aug 04 '11 at 18:29
  • In my experience I always have had to do it as I mentioned with setShowsUserLocation: followed by showUserLocation: – rich Aug 04 '11 at 18:33
  • Woops, I had meant to write "self.mapView.showUserLocation = YES". Anyway, I figured it out (kinda). Since it was coming in from a Xib, I just checked the box in interface builder that says "Shows User Location". No idea I wasn't able to do it programmatically, but it works now. – Tim Aug 04 '11 at 19:16
  • Progress is progress but I feel that some delegate call backs may not function properly later. More information about this problem can be found here: http://stackoverflow.com/questions/2443342/how-to-display-user-location-in-mapkit also why are you using CLLocationManager for callbacks instead of this: - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { } – rich Aug 04 '11 at 19:24