ios - why does it not zoom? -
new objective c!
im trying make mapview zoom. i've copied code assignment in book, somehow doesn't zoom. shows unzoomed mapview.
any suggestions? see viewcontroller code below.
also - few words on difference of importing header file , @class directive great!?
thanks in advance
#import "trackviewcontroller.h" #import "mainwindowviewcontroller.h" #import <mapkit/mapkit.h> @class mainwindowviewcontroller; @implementation trackviewcontroller - (id) initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self=[super initwithnibname:nibnameornil bundle:nibbundleornil]; if(self) { locationmanager = [[cllocationmanager alloc]init]; [locationmanager setdelegate:self]; [locationmanager setdesiredaccuracy:kcllocationaccuracybest]; } return self; } -(ibaction) back:(id)sender { [self dismissviewcontrolleranimated:yes completion:nil]; } -(void) findlocation; { [locationmanager startupdatinglocation]; } -(void) foundlocation:(cllocation *)loc { cllocationcoordinate2d coord = [loc coordinate]; mkcoordinateregion region = mkcoordinateregionmakewithdistance(coord, 100, 100); [worldview setregion:region]; [locationmanager stopupdatinglocation]; } -(void)viewdidload { [worldview setshowsuserlocation:yes]; [worldview setmaptype:mkmaptypehybrid]; } -(void)dealloc { [locationmanager setdelegate:nil]; } - (void) locationmanager:(cllocationmanager *) manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation { nstimeinterval t = [[newlocation timestamp] timeintervalsincenow]; if(t<180){ return; } [self foundlocation:newlocation]; } -(void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error { nslog(@"could not find location: %@", error); } @end
the thing notice change setregion line to:
[worldview setregion:region animated:yes];//instead of setregion
-the setregion:
documentation states:
the area displayed map view
-while setregion:animated:
documentation states:
changes visible region , optionally animates change
otherwise, recommend printing out cllocationcoordinate2d
object , ensuring valid.
Comments
Post a Comment