objective c - Use CLLocationManager and MKReverseGeocoder to get name of city -
i trying name of city of user's current location using mkreversegeocoder has errors cannot recognize. here details:
it has errors cannot recognize
undefined symbols: ".objc_class_name_cllocationmanager", referenced from: literal-pointer@__objc@__cls_refs@cllocationmanager in mapviewcontroller.o "_kcllocationaccuracynearesttenmeters", referenced from: _kcllocationaccuracynearesttenmeters$non_lazy_ptr in mapviewcontroller.o ld: symbol(s) not found collect2: ld returned 1 exit status
here;s code:
mapviewcontroller.m // // mapviewcontroller.m // map // // created ashutosh tiwari on 7/23/10. // copyright isu 2010. rights reserved. // #import <mapkit/mapkit.h> #import "mapviewcontroller.h" @implementation mapviewcontroller // implement viewdidload additional setup after loading view, typically nib. - (void)viewdidload { cllocationmanager *locationmanager = [[[cllocationmanager alloc] init] autorelease]; locationmanager.delegate = self; locationmanager.desiredaccuracy = kcllocationaccuracynearesttenmeters; [locationmanager startupdatinglocation]; [super viewdidload]; } - (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation { mkreversegeocoder *geocoder = [[mkreversegeocoder alloc] initwithcoordinate:newlocation.coordinate]; geocoder.delegate = self; [geocoder start]; } - (void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error { nslog(@"locationmanager:%@ didfailwitherror:%@", manager, error); } - (void)reversegeocoder:(mkreversegeocoder *)geocoder didfindplacemark:(mkplacemark *)placemark { mkplacemark * myplacemark = placemark; nsstring *kabpersonaddresscitykey; nsstring *city = [myplacemark.addressdictionary objectforkey:(nsstring*) kabpersonaddresscitykey]; } - (void)reversegeocoder:(mkreversegeocoder *)geocoder didfailwitherror:(nserror *)error { nslog(@"reversegeocoder:%@ didfailwitherror:%@", geocoder, error); } - (void)dealloc { [super dealloc]; } @end
add corelocation.framework
link project (target settings/ linked libraries / add / choose corelocation.framework)
add: briefly each method does:
viewdidload:
createscllocationmanager
instance , starts updating location - current user coordinateslocationmanager:didupdatetolocation:
gets called when cllocationmanager receives user coordinates. can pass themmkreversegeocoder
information of user location (country, city etc)locationmanager:didfailwitherror:
,reversegeocoder:didfailwitherror:
handle possible errors - log them in current implementationreversegeocoder:didfindplacemark:
gets called whenmkreversegeocoder
finds info coordinate, can retrieve info need corresponding fields ofmkplacemark
instance get.
kabpersonaddresscitykey
- key string city field in placemark address dictionary. defined in abperson.h header because address fields placemark , abrecord address same. use key may need link addressbook
framework well.
Comments
Post a Comment