parse.com - Swift fit annotations -


i have few locations in parse i'm query-ing. shows annotations zoom last one. how can find max , min latitudes , longitudes , make them fit ?

there plenty of these on stackoverflow they're in objective-c.

enter image description here

the examples in objective-c still valid since underlying sdk/api still same -- being called using different language (and there's documentation).

to show annotations, there 2 ways it:

  1. use convenient showannotations method. pass array of annotations , automatically calculate reasonable region display. call after adding annotations (after for loop). in fact, showannotations add annotations if aren't on map. show annotations on map, pass map's own annotations array. example:

    self.mapview.showannotations(self.mapview.annotations, animated: true) 
  2. if not happy default region calculated showannotations, can calculate 1 yourself. instead of calculating minimum/maximum latitudes , longitudes, etc, prefer use built-in mkmaprectunion function create mkmaprect fits annotations , call setvisiblemaprect(maprect,edgepadding,animated) lets 1 conveniently define padding in screen points around fitted map rect. technique found in map view sample app apple. example:

    var allannmaprect = mkmaprectnull  object in objects! {     //existing code creates annotation...     //existing code calls addannotation...      let thisannmappoint = mkmappointforcoordinate(annotation.coordinate)     let thisannmaprect = mkmaprectmake(thisannmappoint.x, thisannmappoint.y, 1, 1)     allannmaprect = mkmaprectunion(allannmaprect, thisannmaprect) }  //set inset (blank space around annotations) needed... //these numbers in screen cgpoints... let edgeinset = uiedgeinsetsmake(20, 20, 20, 20)  self.mapview.setvisiblemaprect(allannmaprect, edgepadding: edgeinset, animated: true) 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -