0

I have an iOS app with a map view. I have added an annotation to the map. I would like to programmatically move the map, so that the annotation is near the top part of the MKMapView.

This is what is currently happening:

enter image description here

I want to move the map so that the annotation is shown like this:

enter image description here

This is the code that I have tried so in order to add the annotation, but I can't get the map to move in the correct place:

// Set the map view coordinates.
    MKCoordinateRegion region = { {0.0, 0.0}, {0.0, 0.0} };
    region.center.latitude = coordinate.latitude;
    region.center.longitude = coordinate.longitude;
    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;
    [main_map setRegion:region animated:YES];

    // Set the map view pin.
    MapViewer *ann = [[MapViewer alloc] init];
    ann.title = @"British Red Cross shop";
    ann.subtitle = @"Unit 4 Borough Fields Shopping Centre, Royal Wootton Basset";
    ann.coordinate = region.center;
    [main_map addAnnotation:ann];
Cœur
  • 37,241
  • 25
  • 195
  • 267
Supertecnoboff
  • 6,406
  • 11
  • 57
  • 98
  • I have never been able to get setRegion to work exactly the way I wanted. It seems to shift the region to the next whole zoom level. I filed a bug on it years ago, but as far as I know it was never fixed. – EricS Jun 14 '15 at 15:46
  • 1
    I'm a little confused as to what you've tried, though. Can't you just set the latitude a little lower than your coordinate, thus shifting the map upwards? – EricS Jun 14 '15 at 15:56
  • @EricS But how do I reduce the latitude value? Because when you change latitude values, even by a tiny bit, how do you know where on the map its going to be? – Supertecnoboff Jun 18 '15 at 06:04
  • @EricS And how much should I reduce the latitude by? – Supertecnoboff Jun 18 '15 at 06:04
  • @EricS Are you saying I should try something like ```region.center.latitude = coordinate.latitude - 0.001;``` – Supertecnoboff Jun 18 '15 at 06:05
  • 1
    Or, better, use latitude delta of the span of the region: http://stackoverflow.com/a/15421512/1271826. You saw that answer, so I'm not sure why you didn't try that here. – Rob Jun 18 '15 at 07:58
  • @Rob Thanks very much, in the end that worked for me :) If you put that as an answer I will tick it :) – Supertecnoboff Jun 20 '15 at 12:04

0 Answers0