ios - Gps map is working in iphone but not working in ipad? -


i developing universal app. here developing gps map concept working fine in iphone not working in ipad. requirements getting current location using gps & gave 1 destination place, have 1 marker line current location destination places (ex:banglore(current location) mumbai (destination location)).

this working in iphone in ipad not working showing google map. need implement requirements ipad code base.

could please me resolve issues.

- (nsstring *)stringwithdistance:(double)distance {     nslog(@"%f",distance);      nsstring *format;     if (distance < meters_cutoff) {         format = @"%@ metres";     } else {         format = @"%@ km";         distance = distance / 1000;     }       return [nsstring stringwithformat:format, [self stringwithdouble:distance]]; } // return string of number 1 decimal place , commas & periods based on locale. - (nsstring *)stringwithdouble:(double)value {     nsnumberformatter *numberformatter = [[nsnumberformatter alloc] init];     [numberformatter setlocale:[nslocale currentlocale]];     [numberformatter setnumberstyle:nsnumberformatterdecimalstyle];     [numberformatter setmaximumfractiondigits:2];     return [numberformatter stringfromnumber:[nsnumber numberwithdouble:value]]; }  - (void)viewdidload {     [super viewdidload];     devicetype = [uidevice currentdevice].model;     nslog(@"%@",school11);     nslog(@"lat%@",lat);     nslog(@"%@device",devicetype);     if (!isiphone5)     {         // self.footer.frame=cgrectmake(0, 448, 320, 32);       }        nslog(@"current identifier: %@", [[nsbundle mainbundle] bundleidentifier]);       // additional setup after loading view, typically nib. } -(void)viewwillappear:(bool)animated {     if (!isiphone5)     {        //  self.footer.frame=cgrectmake(0, 448, 320, 32);       }       [self currentlocation];  } -(void)currentlocation{     locationmanager = [[cllocationmanager alloc]init];     locationmanager.delegate = self;     locationmanager.desiredaccuracy = kcllocationaccuracybest;      [locationmanager startupdatinglocation];       if ([devicetype isequaltostring:@"ipad"]) {           mapview = [[[mapview alloc] initwithframe:                     cgrectmake(0, 50, 768, 1000)] autorelease];          [self.view addsubview:mapview];       }     else{         if (!isiphone5)         {             mapview = [[[mapview alloc] initwithframe:                         cgrectmake(0, 50, 320, 450)] autorelease];              [self.view addsubview:mapview];         }         else{             mapview = [[[mapview alloc] initwithframe:                         cgrectmake(0, 50, 320,  800)] autorelease];              [self.view addsubview:mapview];         }     }          cllocation *loca = [[cllocation alloc] initwithlatitude:13.2339538 longitude:80.3323613];      cllocation *locb = [[cllocation alloc] initwithlatitude:28.889816 longitude:77.3418147];      cllocationdistance distance = [loca distancefromlocation:locb];     nslog(@"%f meters",distance);     nslog(@"%@",    [self stringwithdistance:distance]);   } - (void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error {     nslog(@"didfailwitherror: %@", error);     uialertview *erroralert = [[uialertview alloc]                                initwithtitle:@"error" message:@"failed location" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil];     [erroralert show]; }     // cllocati - (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation {     nslog(@"didupdatetolocation: %@", newlocation);     cllocation *currentlocation = newlocation;      if (currentlocation != nil) {          place* home = [[[place alloc] init] autorelease];         home.name = @"vivero international pre-school";        // home.description = @"coyaji rd, nilanjali society, kalyani nagar pune,maharashtra 411006 india";         cllocationcoordinate2d center;         center=[self getlocationfromaddressstring:@"madurai"];         latfrom=&center.latitude;         lonfrom=&center.longitude;          double latt = [lat floatvalue];         double lann = [lon floatvalue];         home.latitude=latt;         home.longitude=lann;         cllocation *loca = [[cllocation alloc] initwithlatitude:home.latitude longitude:home.longitude];            place* office = [[[place alloc] init] autorelease];         office.name = @"office";         office.description = @"current";         office.latitude = currentlocation.coordinate.latitude;         office.longitude = currentlocation.coordinate.longitude;         [mapview showroutefrom:home to:office];          cllocation *locb = [[cllocation alloc] initwithlatitude:office.latitude longitude:office.longitude];          cllocationdistance distance = [loca distancefromlocation:locb];         nslog(@"%f meters",distance);         nslog(@"%@",    [self stringwithdistance:distance]);       }     // stop location manager     [locationmanager stopupdatinglocation]; }  - (void)dealloc {     [super dealloc]; } - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. } -(cllocationcoordinate2d) getlocationfromaddressstring: (nsstring*) addressstr {     double latitude = 0, longitude = 0;     nsstring *esc_addr =  [addressstr stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];     nsstring *req = [nsstring stringwithformat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];     nslog(@"%@",req);     nsstring *result = [nsstring stringwithcontentsofurl:[nsurl urlwithstring:req] encoding:nsutf8stringencoding error:null];     if (result) {         nsscanner *scanner = [nsscanner scannerwithstring:result];         if ([scanner scanuptostring:@"\"lat\" :" intostring:nil] && [scanner scanstring:@"\"lat\" :" intostring:nil]) {             [scanner scandouble:&latitude];             if ([scanner scanuptostring:@"\"lng\" :" intostring:nil] && [scanner scanstring:@"\"lng\" :" intostring:nil]) {                 [scanner scandouble:&longitude];             }         }     }     cllocationcoordinate2d center;     center.latitude=latitude;     center.longitude = longitude;     nslog(@"view controller location logitute : %f",center.latitude);     nslog(@"view controller location latitute : %f",center.longitude);     return center;  } 

debuging in iphone means working in ipad below method not calling

- (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation {     nslog(@"didupdatetolocation: %@", newlocation);     cllocation *currentlocation = newlocation;      if (currentlocation != nil) {          place* home = [[[place alloc] init] autorelease];         home.name = @"vivero international pre-school";          cllocationcoordinate2d center;         center=[self getlocationfromaddressstring:@"madurai"];         latfrom=&center.latitude;         lonfrom=&center.longitude;          double latt = [lat floatvalue];         double lann = [lon floatvalue];         home.latitude=latt;         home.longitude=lann;         cllocation *loca = [[cllocation alloc] initwithlatitude:home.latitude longitude:home.longitude];            place* office = [[[place alloc] init] autorelease];         office.name = @"office";         office.description = @"current";         office.latitude = currentlocation.coordinate.latitude;         office.longitude = currentlocation.coordinate.longitude;         [mapview showroutefrom:home to:office];          cllocation *locb = [[cllocation alloc] initwithlatitude:office.latitude longitude:office.longitude];          cllocationdistance distance = [loca distancefromlocation:locb];         nslog(@"%f meters",distance);         nslog(@"%@",    [self stringwithdistance:distance]);       }     // stop location manager     [locationmanager stopupdatinglocation]; } 

finally getting error message in ipad:

trying start mapkit location updates without prompting location authorization. must call -[cllocationmanager requestwheninuseauthorization] or -[cllocationmanager requestalwaysauthorization] 

please guide me how resolve issue.

thanks in advance.

on ios 8 have use following code.

if (is_os_8_or_later)     {         if ([self.locationmanager respondstoselector:@selector(requestalwaysauthorization)])         {             [self.locationmanager requestalwaysauthorization];         }      }       [self.locationmanager startupdatinglocation]; 

and use key nslocationalwaysusagedescription in info.plist , give description.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -