geolocation - startUpdatingLocation not being fired in iOS -
i'm trying write simple geolocation app find users position in ios. when user presses button, user's position found , displayed, , should changing when startupdatinglocation fired. startupdatinglocation isn't being fired. here's code:
in viewcontroller.h
#import <uikit/uikit.h> #import <mapkit/mapkit.h> #import <corelocation/corelocation.h> @interface cgviewcontroller : uiviewcontroller<cllocationmanagerdelegate> @property (strong, nonatomic) iboutlet uitextfield *namefield; - (ibaction)butstart:(id)sender; @property (strong, nonatomic) iboutlet mkmapview *map; @property (strong, nonatomic) cllocationmanager *locationmanager; @property (strong, nonatomic) iboutlet uilabel *latitude; @property (strong, nonatomic) iboutlet uilabel *longitude; @property (strong, nonatomic) iboutlet uilabel *altitude; @end and in viewcontroller.m:
- (ibaction)butstart:(id)sender { self.locationmanager=[[cllocationmanager alloc] init]; if([cllocationmanager locationservicesenabled]){ self.locationmanager.delegate=self; self.locationmanager.distancefilter=1; [self.locationmanager startupdatinglocation]; } } (void)locationmanager:(cllocationmanager *)manager didupdatelocations:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation { nslog( @"new location = %@", [newlocation description] ); mkcoordinatespan span; span.latitudedelta = 0.2; span.longitudedelta = 0.2; mkcoordinateregion region; region.span = span; region.center = newlocation.coordinate; map.showsuserlocation = yes; self.latitude.text = [nsstring stringwithformat:@"%.3f", newlocation.coordinate.latitude]; self.longitude.text = [nsstring stringwithformat:@"%.3f", newlocation.coordinate.longitude]; } i've tried leave out unnecessary code, map have. every sample i've seen has locationmanager stuff being set in appdelegate.h/.m, whereas i'm trying call when user presses button. i'm not sure why not being called.
i have implement code in project , working fine .
-if run project in simulator first time location service allow , disallow message comes , if allow method called please replace yoyr method this
- (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation {
float currentlangitude = newlocation.coordinate.longitude; float currentlatitude = newlocation.coordinate.latitude; nslog( @"new location lat = %f long = %f", currentlangitude,currentlatitude ); }
thanks.
Comments
Post a Comment