objective c - Store iPhone Location as NSString? -


i new objective-c & building first app. trying output iphones location string used in json request.

i have request built unsure how iphones location, let alone string & apple documentation finding difficult follow.

how can this?

edit: i've seen how implement location so:

- (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation        fromlocation:(cllocation *)oldlocation { cllocationdegrees latitude = newlocation.coordinate.latitude; cllocationdegrees longitude = newlocation.coordinate.longitude; } 

however unsure put this, isn't object it?

i don't need initialize it?

i tried editing return newlocation stirng instead of void, how call it?

what input need (cllocationmanager *)?

the cllocationmanager class allow track current location.

if want use find location, that's need :

// create instance of cllocationmanager class : cllocationmanager *locationmanager = [[cllocationmanager alloc] init];  // set delegate of instance : locationmanager.delegate = self; // set controller <cllocationmanagerdelegate>.  // update location : [locationmanager startupdatinglocation]; 

now, everytime cllocationmanager instance did update, delegate method called :

- (void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations; 

which means everytime locationmanager update location, method called.

now can overwrite method adding in .m file :

- (void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations {     // whatever want here } 

for example, if want store current coordinates can :

declare in .h :

float latitude; float longitude; 

then complete delegate method (write in .m) :

- (void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations {     latitude = [manager location].coordinate.latitude;     longitude = [manager location].coordinate.longitude; } 

now can store values in nsstring @amar answered.

i have edited answer 6 times hope answer question , :d.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -