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.
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:
use convenient
showannotations
method. pass array of annotations , automatically calculate reasonable region display. call after adding annotations (afterfor
loop). in fact,showannotations
add annotations if aren't on map. show annotations on map, pass map's ownannotations
array. example:self.mapview.showannotations(self.mapview.annotations, animated: true)
if not happy default region calculated
showannotations
, can calculate 1 yourself. instead of calculating minimum/maximum latitudes , longitudes, etc, prefer use built-inmkmaprectunion
function createmkmaprect
fits annotations , callsetvisiblemaprect(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
Post a Comment