ios - Select Statement Parse Objective C -


i have begun development 'objective candparse`. have function in app allowing user enter in new climb. data stored in table of mine in parse. add climb map view portion of app.

i wanting write select statement stores of results query array of sort , dump map view portion. way thinking dynamically add map pin map every time new area added, if not exist of course.

i .net developer , in scenario grab data , dump data table , real there.... not sure of best practice on doing above scenario in objective c.

i post code map below :

mappin.h

#import <foundation/foundation.h> #import <mapkit/mapkit.h>  @interface mappin : nsobject <mkannotation> { cllocationcoordinate2d coordinate;  nsstring *title; nsstring *subtitle; }  @property (nonatomic, assign) cllocationcoordinate2d coordinate; @property (nonatomic, copy) nsstring *title; @property (nonatomic, copy) nsstring *subtitle;  @end 

mappin.m

#import "mappin.h"  @implementation mappin  @synthesize coordinate, title, subtitle;  @end 

mapviewcontroller.h

#import <uikit/uikit.h> #import <mapkit/mapkit.h>  @interface mapviewcontroller : uiviewcontroller {     mkmapview *mapview; }  @property (nonatomic, retain) iboutlet mkmapview *mapview;  -(ibaction)setmap:(id)sender;  -(ibaction)getlocation:(id)sender;  -(ibaction)directions:(id)sender;  @end 

mapviewcontroller.m

#import "mapviewcontroller.h" #import "mappin.h"  @interface mapviewcontroller ()<mkmapviewdelegate>  @end  @implementation mapviewcontroller  @synthesize mapview;  - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil {     self = [super initwithnibname:nibnameornil bundle:nibbundleornil];     if (self) {     // custom initialization     }     return self; }  - (void)viewdidload { [super viewdidload];  mapview.delegate = self;  //new //[self.mapview setshowsuserlocation:yes];  //moss preserve annotation , map pin mappin *mosspreserveannotation = [[mappin alloc] init]; mosspreserveannotation.title = @"moss rock preserve boulder fields"; mosspreserveannotation.subtitle = @"hoover, al"; mosspreserveannotation.coordinate = cllocationcoordinate2dmake(33.3816566, -86.8415451); [mapview addannotation:mosspreserveannotation];   //setup map mkcoordinateregion mapcoordregion; mapcoordregion.center.latitude = 39; mapcoordregion.center.longitude = -97; mapcoordregion.span.latitudedelta = 60.0; mapcoordregion.span.longitudedelta = 60.0;  [mapview setregion:mapcoordregion]; }  - (void)viewwillappear:(bool)animated { [super viewwillappear:animated];  [[uiapplication sharedapplication] setstatusbarstyle:uistatusbarstyledefault]; self.navigationcontroller.navigationbar.hidden = no; }   - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. }  - (void)mapview:(mkmapview *)mapview annotationview:(mkannotationview *)view calloutaccessorycontroltapped:(uicontrol *)control {  // create mkmapitem pass maps app mkplacemark *placemark = [[mkplacemark alloc]  initwithcoordinate:view.annotation.coordinate                                                 addressdictionary:nil]; mkmapitem *mapitem = [[mkmapitem alloc] initwithplacemark:placemark]; [mapitem setname:view.annotation.title];  nsdictionary *launchoptions = @{mklaunchoptionsdirectionsmodekey : mklaunchoptionsdirectionsmodedriving};  // "current user location" mkmapitem mkmapitem *currentlocationitem = [mkmapitem mapitemforcurrentlocation]; [mkmapitem openmapswithitems:@[currentlocationitem, mapitem]                launchoptions:launchoptions]; }  - (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id<mkannotation>)annotation { mkannotationview *annotationview = [[mkpinannotationview alloc] initwithannotation:annotation                                                                    reuseidentifier:@"mkpinannotationview"]; annotationview.canshowcallout = yes;  uibutton *detailbutton = [uibutton buttonwithtype:uibuttontypeinfolight]; [detailbutton settintcolor:[uicolor colorwithred:183/255.0 green:207/255.0 blue:85/255.0 alpha:0.5]];  annotationview.rightcalloutaccessoryview = detailbutton;  return annotationview; }  -(ibaction)setmap:(id)sender; { switch (((uisegmentedcontrol *) sender).selectedsegmentindex) {     case 0:         mapview.maptype = mkmaptypestandard;         break;     case 1:         mapview.maptype = mkmaptypesatellite;         break;     case 2:         mapview.maptype = mkmaptypehybrid;         break;      default:         break; } }  -(ibaction)getlocation:(id)sender; { mapview.showsuserlocation = yes; }  -(ibaction)directions:(id)sender; { nsstring *urlstring = @"http://maps.apple.com/maps?daddr=33.3816566,-86.8415451"; [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:urlstring]]; }  @end 

sorry dump lot of code in here... wanted provide had.

before answering, notes: start methods in lower case, it's common practice. pin , annotation 2 diferent concepts, let's pin view , annotation model (or business object), it's better if call mappin mapannontation (or annontation, cause map redundant). in close future going have custom pins, subclass of mkannotationview.

for reply, have app retrieves places current map area parse (www.sharewifiapp.com). code , below explanations:

#pragma mark mkmapviewdelegate - (void)mapview:(mkmapview *)mapview regionwillchangeanimated:(bool)animated {     [self.hotspotsquery cancel]; }  - (void)mapview:(mkmapview *)mapview regiondidchangeanimated:(bool)animated {      //dddebuglog(@"zoom %lu", (unsigned long)[self.mapview zoomlevel]);      // retrieve hotspots using filtering , current view port     self.hotspotsquery = [pfquery querywithclassname:[swhotspot parseclassname]];     mkmaprect mrect = self.mapview.visiblemaprect;     mkmappoint nemappoint = mkmappointmake(mkmaprectgetmaxx(mrect), mrect.origin.y);     mkmappoint swmappoint = mkmappointmake(mrect.origin.x, mkmaprectgetmaxy(mrect));     cllocationcoordinate2d necoord = mkcoordinateformappoint(nemappoint);     cllocationcoordinate2d swcoord = mkcoordinateformappoint(swmappoint);     pfgeopoint* swgeopoint=[pfgeopoint geopointwithlatitude:swcoord.latitude longitude:swcoord.longitude];     pfgeopoint* negeopoint=[pfgeopoint geopointwithlatitude:necoord.latitude longitude:necoord.longitude];     [self.hotspotsquery wherekey:@"location" withingeoboxfromsouthwest:swgeopoint tonortheast:negeopoint];     [self.hotspotsquery includekey:@"owner"];     [self.hotspotsquery orderbydescending:@"updatedat"];     self.hotspotsquery.limit=1000;       self.loadinghotspotsactivityview.hidden=no;     [self.hotspotsquery findobjectsinbackgroundwithblock:^(nsarray *hotspots, nserror *error) {          self.loadinghotspotsactivityview.hidden=yes;         if (error) {             ddlogerror(@"error retrieving hotspots: %@", [error userinfo][@"error"]);          } else {             // test.              /*             nslog(@"retrieved: %lu", (unsigned long)objects.count);             [self.mapview removeannotations:self.mapview.annotations];             [self.mapview addannotations:objects];             */                    // remove hotspots not in current response (hotstpots)                 nsmutablearray* hotspotstoremove=[self.mapview.annotations mutablecopy];                 [hotspotstoremove removeobjectsinarray:hotspots];                 [self.mapview removeannotations:hotspotstoremove];                  // add hotpots current response not in original set                 nsmutablearray* hotspotstoadd=[hotspots mutablecopy];                 [hotspotstoadd removeobjectsinarray:self.mapview.annotations];                 [self.mapview addannotations:hotspotstoadd];          }     }]; } 

important points: -save parse query can cancel it. -cancel when user starts moving map, , launch new request when user stops moving map. -every time receive new places parse query, can remove annotations , put new ones, performance point of view that's not nice. if want try code says test. -if want improve performance, follow logic, removes annotations not in current reply , add new places if not in map.

hope helps.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -