0

I would like to add an icon to the map view so that when people click on the icon, they see their current location.

I want to add the icon on the bottom left of this image:

enter image description here

How can I add that image to my map view?

I tried doing:

UIImage * l =  [UIImage imageNamed: @"location.png"];
UIImageView * lb = [[UIImageView alloc] initWithImage: l];
[lb setFrame: CGRectMake(0, 300, lb.frame.size.width, lb.frame.size.height)];
[self.mapview addSubview: lb];
woz
  • 10,888
  • 3
  • 34
  • 64
  • I think you need a `UIButton` instead of `UIImageView`, but did you try `[self.view addSubview:lb]`? – woz Jul 12 '13 at 14:12
  • Also see http://stackoverflow.com/questions/9876157/is-the-current-location-compass-heading-button-available-in-the-ios-sdk to use the built-in button (assuming you are using MKMapView and not the Google map view). –  Jul 12 '13 at 14:21

1 Answers1

2

I'd add it as a sibling to the map view instead. Doing so is safer, as there's no guarantee that the map view isn't manipulating its bounds when you pan/zoom (which would cause your icon to move as well).

[self.view addSubview:lb];
Tyler
  • 371
  • 1
  • 7