iphone - iOS - if user allow using his current location or not -


in app in map view want show nearest 10 stores user's current location

but first have take current location first can show stores according user's location

in first start of app app ask user if allow current location or not must

if user allow list stores on map else go main page

now using code below:

 mtmap.showsuserlocation=yes; mymanager=[[cllocationmanager alloc] init]; mymanager.delegate=self; cllocation *location = [mymanager location]; cllocationcoordinate2d coordinate2 = [location coordinate];  nsstring *latitude1 = [nsstring stringwithformat:@"%f", coordinate2.latitude];  nsstring *longitude1 = [nsstring stringwithformat:@"%f", coordinate2.longitude];  nsstring *myurl = [[nsstring alloc] initwithformat:@"http://www.xxxx.com/xxxx/aaaaa.ashx?term=%@,%@",latitude1,longitude1]; nsdata *data = [nsdata datawithcontentsofurl:[nsurl urlwithstring:myurl]]; nsinputstream *datastream=[[nsinputstream alloc]initwithdata:data];  [datastream open]; if(datastream) {      nserror *err=nil;     id jsonobject=[nsjsonserialization jsonobjectwithstream:datastream options:nsjsonreadingallowfragments error:&err];     if([jsonobject respondstoselector:@selector(objectforkey:)])     {         //fill arr     } } 

but doesn't work first time when user opens app because of late allowing or getting current location late can't reach can't show nearest places

there can problem logic. mean may shouldn't job in viewdidload

so how can solve problem?

instead of doing under viewdidload section, inserting code in method?

// delegate method cllocationmanagerdelegate protocol.  - (void)locationmanager:(cllocationmanager *)manager  didupdatetolocation:(cllocation *)newlocation  fromlocation:(cllocation *)oldlocation  {  cllocation *location = newlocation; ... 

that make code run once user's location updated. add if statement inside method check if first time code has been run , if not return.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -