1

I have just build an swift app that takes data+coords from dynamoDB and puts it onto the ios mapkit. There are two sets of coords: one for current user location and one from dynamoDB. I want these coords to be able to update inside the map, but do not want the actual mapView to zoom and move at all (only the user can zoom and move).

I have achieved everything above except the last part. Currently whenever the annotations are added and mapView.showAnnotations is called, the mapView zooms and moves to enclose the annotations. How do I disable this?

piyushj
  • 1,546
  • 5
  • 21
  • 29
yks
  • 79
  • 1
  • 6
  • FINAL EDIT: after some searching, i changed mapView.showAnnotations() to mapView.addAnnotations(). This solved the problem by revealing your annotations but not updating your mapView positioning. – yks Jul 18 '16 at 10:17

2 Answers2

1

To show mapView annotations without updating mapView zoom and constraints, use addAnnotations() rather than showAnnotations.

yks
  • 79
  • 1
  • 6
0

I am guessing that you used code from online (which we all do, no worries) and that your code looked something like this. If I am right, then you likely have a line somewhere like this:

[map setRegion:scaledRegion animated:YES];

That line is the issue. You need to use some sort of boolean to make it so that it only happens once. So you could set the boolean has_mapped = false until you have called your update method once, at which point it = true. Then change your line to say something like,

if (has_mapped)
    [map setRegion:scaledRegion animated:YES]; 
Community
  • 1
  • 1
Max von Hippel
  • 2,856
  • 3
  • 29
  • 46
  • Yes - you are right, I call that line in ViewDidLoad. However when I mark it out, there doesn't seem to be any effect on the auto zooming - the map still continue to zoom to annotations and north. I have checked the code and I don't think there is another instance of setRegion. Do you think it is set to autozoom by default? – yks Jul 18 '16 at 06:57
  • Interesting! When it refreshes, what code gets called? I would check there and see if there is anything related to the bounding box. Alternatively, could the viewDidLoad be getting called again for some reason? You could use NSLog statements to track it down. Also, try setting it to a specific hard coded region in view did load, and see if it changes upon refresh. – Max von Hippel Jul 18 '16 at 07:03
  • Is it possible 'mapView.showAnnotations()' is zooming and moving the mapView ? I cant seem to find any other points in the app where it could possibly move.. – yks Jul 18 '16 at 09:45
  • 1
    FINAL EDIT: after some searching, i changed mapView.showAnnotations() to mapView.addAnnotations(). This solved the problem by revealing your annotations but not updating your mapView positioning. – yks Jul 18 '16 at 10:17
  • Awesome! Sorry I was wrong in my analysis but glad I was hopefully helpful in pointing you somewhat in the correct direction to solve he problem haha :) – Max von Hippel Jul 18 '16 at 15:33
  • @yks you should write a short answer saying that and accept it – Max von Hippel Jul 18 '16 at 15:33