ios - Displaying MKAnnotationViews that are within the bounds of the visible mapview -


i'm querying server list of locations closest user based on observable portion of mapview.

i'm not entirely sure on how this, should send center lat , long of mapview's visible region , search results based on nearest radius?

i know mkmapview has 2 properties called region , visiblemaprect. should use 1 of those, , if so, 1 more appropriate based on question?

edit i'm looking implement functionality that's identical apple maps , yelp app when search nearby locations , shows what's relevant based off visible portion of map view.

edit 2 have seen lot of people break visible portion of mapview quadrants, commonly nw,ne,sw , se. however, i'm still not entirely sure why theyr'e doing this. know best way query end, contains lat , long each location, find locations exist on mapview.

i have looked everywhere on stackoverflow , found similar question here. however, doesn't answer question , there's no mention of visiblemaprect because it's on 5 years old.

any tremendously appreciated.

so need provide server call these 2 coord bottomleft , topright 4 points together.

  1. if lat of location > bottomleft.lat , if lat of location < topright.lat
  2. if long of location > bottomleft.long , if long of location < topright.long

ios code make server call these 4 variables parameters

fun viewdidload() {    super.viewdidload()    self.mapview.delegate = self }   func mapview(mapview: mkmapview, regiondidchangeanimated animated: bool) {    // using region    var span: mkcoordinatespan = mapview.region.span    var center: cllocationcoordinate2d = mapview.region.center     // farthest lat point left    var farthestleft = center.latitude - span.latitudedelta * 0.5    // farthest lat point right    var farthestright = center.latitude + span.latitudedelta * 0.5    // farthest long point in upward direction    var farthesttop = center.longitude - span.longitudedelta * 0.5    // farthest long point in downward direction    var farthestbottom = center.longitude + span.longitudedelta * 0.5    var swcoord = mkcoordinateformappoint(farthestbottom, farthestleft)    var necoord = mkcoordinateformappoint(farthesttop, farthestright)      // using visiblemaprect    var maprect = mapview.visiblemaprect    // top right coordinate    var necoord = getcoordinatefrommaprectanglepoint(mkmaprectgetmaxx(maprect), y: maprect.origin.y)    // bottom left coordinate    var swcoord = getcoordinatefrommaprectanglepoint(maprect.origin.x, y: mkmaprectgetmaxy(maprect))    // not needed useful    // var nwcoord = getcoordinatefrommaprectanglepoint(mkmaprectgetminx(maprect), y: maprect.origin.y)    // var secoord = getcoordinatefrommaprectanglepoint(mkmaprectgetmaxx(maprect), y: mkmaprectgetmaxy(maprect))   }  func getcoordinatefrommaprectanglepoint(x: double, y: double) -> cllocationcoordinate2d {    var mappoint = mkmappointmake(x, y)    return mkcoordinateformappoint(mappoint) } 

if have anymore questions comment


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -