ios6 - Trying to Get Current Location integrated with iOS project -
so i'm attempting integrate user's current location ios project - i'm using third part code build out map pinpoints - have these frameworks integrated:
#import <uikit/uikit.h> #import <corelocation/corelocation.h> #import <quartzcore/quartzcore.h> #import <mapkit/mapkit.h>
here's code pinpoints - appreciated:
#import "asymap.h" @implementation asymap @synthesize currentannotation,mapannotations,map,prompt,mapfromlink,selectedannotationid,selectedannotationindex,showothers,usecustomtitle,customtitle; /** * class constructor */ -(id)init{ self = [super init]; if(self){ usecustomtitle = false; mapfromlink = false; showothers = false; map = [[asymapobject alloc] init]; [map addonview:self.view]; } return self; } /** * overwrite set page method in * order show selected annotation * link */ -(void)setpage:(nsdictionary *)page{ nsdictionary *metas = [page valueforkey:@"metas"]; if([metas valueforkey:@"selectedannotationpagetitle"] && ![[[metas valueforkey:@"selectedannotationpagetitle"] stringvalue] isequaltostring:@""] && customtitle == nil){ usecustomtitle = true; nsstring *newtitle = [metas valueforkey:@"selectedannotationpagetitle"]; customtitle = [[nsstring alloc] initwithstring:[[newtitle stringbyreplacingoccurrencesofstring:@"+" withstring:@" "] stringbyreplacingpercentescapesusingencoding:nsutf8stringencoding]]; } if(usecustomtitle && customtitle != nil){ nsmutabledictionary *pagewithcustomtitle = [[nsmutabledictionary alloc] initwithdictionary:page]; [pagewithcustomtitle setvalue:customtitle forkey:@"title"]; [super setpage:pagewithcustomtitle]; }else{ [super setpage:page]; } if([metas valueforkey:@"annotationfromlink"] && [[[metas valueforkey:@"annotationfromlink"] stringvalue] isequaltostring:@"yes"] && selectedannotationid == nil){ selectedannotationid = [[nsstring alloc] initwithstring:[metas valueforkey:@"selectedannotation"]]; mapfromlink = true; showothers = [[[metas valueforkey:@"showothers"] stringvalue] isequaltostring:@"yes"]; }else if(mapfromlink && selectedannotationid != nil){ mapfromlink = false; nsarray *annotations = [page valueforkey:@"annotations"]; for(int = 0; < [annotations count]; a++){ nsdictionary *annotation = [annotations objectatindex:a]; if([[[annotation valueforkey:@"annotationid"] stringvalue] isequaltostring:selectedannotationid]){ mapfromlink = true; selectedannotationindex = a; break; } } } } /** * set module's name */ -(void)makeprocess{ [self setmodulename:@"map"]; } /** * create basic prompt alert */ -(void)buildmodule{ prompt = [[uialertview alloc] initwithtitle:@"" message:[theme asy__:@"open on maps app?"] delegate:self cancelbuttontitle:[theme asy__:@"no"] otherbuttontitles:[theme asy__:@"yes"], nil]; } /** * set annotations after page data */ -(void)requestedpage:(nsdictionary *)pageinformation{ [self setpage:pageinformation]; if(mapfromlink && !showothers && [[self getpagemapannotations] count] > 0){ nsarray *pageannotations = [self getpagemapannotations]; mapannotations = [[nsarray alloc] initwithobjects:[pageannotations objectatindex:selectedannotationindex],nil]; }else{ mapannotations = [[nsarray alloc] initwitharray:[self getpagemapannotations]]; } [map setmapannotations:mapannotations anddelegate:self]; if(mapfromlink){ [map focusmaponannotationatindex:(showothers ? selectedannotationindex : 0)]; } [map build]; [self hideloading]; [self checkpageoptionbutton]; } /** * module orientation did change */ -(void)moduleorientationdidchange{ [map setframe:cgrectmake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; } #pragma mark - map delegate /** * check if annotation has properties action or prompt opened * on maps app should appear */ -(void)asymapobject:(asymapobject *)mapobject didselectannotation:(nsdictionary *)annotation atindex:(nsinteger)index{ currentannotation = index; if([[annotation valueforkey:@"menuid"] isequaltostring:@"0"] && [[annotation valueforkey:@"pageid"] isequaltostring:@"0"] && [[annotation valueforkey:@"link"] isequaltostring:@""] && [[annotation valueforkey:@"url"] isequaltostring:@""] && [[annotation valueforkey:@"phpfile"] isequaltostring:@""]){ [prompt settitle:[annotation valueforkey:@"title"]]; [prompt show]; }else{ appsifymecore *core = [appsifymecore sharedappsifymecore]; [core basichandlerformultiactionsoption:annotation]; } } #pragma mark - alert view delegate /** * detect if user wants open annotation on maps app, , if * true, method build link , open app */ -(void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex{ if(buttonindex != 1) return; appsifymecore *core = [appsifymecore sharedappsifymecore]; nsdictionary *annotation = [mapannotations objectatindex:currentannotation]; float latitude = [[annotation valueforkey:@"latitude"] floatvalue]; float longitude = [[annotation valueforkey:@"longitude"] floatvalue]; if(![core asyios6]){ nsstring *pinname = [[nsstring alloc] initwithstring:[core encodeurlparameter:[annotation valueforkey:@"title"]]]; int zoom = 13; nsstring *stringurl = [[nsstring alloc] initwithformat:@"http://maps.apple.com/maps?q=%@@%1.6f,%1.6f&z=%d", pinname, latitude, longitude, zoom]; nsurl *url = [[nsurl alloc] initwithstring:stringurl]; [[uiapplication sharedapplication] openurl:url]; }else{ class itemclass = [mkmapitem class]; if (itemclass && [itemclass respondstoselector:@selector(openmapswithitems:launchoptions:)]) { cllocationcoordinate2d coordinate = cllocationcoordinate2dmake(latitude,longitude); mkplacemark *placemark = [[mkplacemark alloc] initwithcoordinate:coordinate addressdictionary:nil]; mkmapitem *item = [[mkmapitem alloc] initwithplacemark:placemark]; item.name = [[annotation valueforkey:@"title"] stringvalue]; [item openinmapswithlaunchoptions:nil]; } } } @end
in init
method, add line
self.showsuserlocation = yes;
Comments
Post a Comment