Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-20-2008, 07:03 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 34
zword is on a distinguished road
Default structure of location-aware app

I have a question regarding the structure for a location-aware application.

My idea:

Use of 2 classes:

a)MyViewController<h.m> --> This class controls the view and initiates the localisation

b)MyLocationController<h.m> --> In this class all things which are needed for the localisation should be calculated.

I've imported the classes from the CoreLocation_Framework in MyLocationController class and added the method "locationManager:didUpdateToLocation:fromLocation: " for the location-updates.
I'vd added another method "- (void)startUpdate" where the CLLocationManager starts the update process e.g. like this:

MyLocationController.m
Code:
myLM = [[CLLocationManager alloc] init]; 
myLM.delegate = self; 
myLM.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; 
myLM.distanceFilter = 100;
[myLM startUpdatingLocation];
I've tried then to call the startUpdate method within the MyViewController class during a button event like this:

Code:
[myLocController startUpdate]
where myLocController is an object of MyLocationController. But running through the debugger the startUpdate is never called. I think a make a conceptual mistake, maybe someone could help me.
zword is offline   Reply With Quote
Old 01-23-2011, 11:09 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 26
petros is on a distinguished road
Default

Hi, I have exactly the same problem. Can you help me please??? I want to update location in a btutton event. This is my code:


- (void)locationManagerCLLocationManager *)manager
didUpdateToLocationCLLocation *)newLocation
fromLocationCLLocation *)oldLocation
{
if (wasFound) return;
wasFound = YES;
CLLocationCoordinate2D loc = [newLocation coordinate];

latitude.text = [NSString stringWithFormat: @"%f", loc.latitude];
longitude.text = [NSString stringWithFormat: @"%f", loc.longitude];
altitude.text = [NSString stringWithFormat: @"%f", newLocation.altitude];
didUpdateToLocationCLLocation *)newLocation;
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
latitude.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
longitude.text = longt;
}

-(IBAction)updateLocation {
locmanager = [[CLLocationManager alloc] init];
locmanager.delegate = self;
locmanager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locmanager.desiredAccuracy = kCLLocationAccuracyBest; // 100 m
[locmanager stopUpdatingLocation];
}
petros is offline   Reply With Quote
Old 01-23-2011, 11:50 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 14
Tomsen is on a distinguished road
Default

@zword: your locmanager variable might be nil. If you're debugging and it is not, then please post the header files and the relevant CoreLocation parts of the m files. right now it is hard to trace, where the problem might be.

@petros
first: what exactly are u doing with the line
Code:
didUpdateToLocation:(NSLocation*)newLocation
? You are calling half a mehtod. Doesn't this line throw a compiler error or warning or is that a custom method u wrote?

second: in your button action, you are constantly reallocation a new LocationManager object. You should alloc and init your manager when the view gets loaded, not in a recurring function (unless u check the iVar for nil).

also you are calling
Code:
stopUpdatingLocation
instead of
Code:
startUpdatingLocation

Last edited by Tomsen; 01-23-2011 at 11:53 AM.
Tomsen is offline   Reply With Quote
Old 01-23-2011, 12:28 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by zword View Post
I have a question regarding the structure for a location-aware application.

My idea:

Use of 2 classes:

a)MyViewController<h.m> --> This class controls the view and initiates the localisation

b)MyLocationController<h.m> --> In this class all things which are needed for the localisation should be calculated.

I've imported the classes from the CoreLocation_Framework in MyLocationController class and added the method "locationManager:didUpdateToLocation:fromLocation: " for the location-updates.
I'vd added another method "- (void)startUpdate" where the CLLocationManager starts the update process e.g. like this:

MyLocationController.m
Code:
myLM = [[CLLocationManager alloc] init]; 
myLM.delegate = self; 
myLM.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; 
myLM.distanceFilter = 100;
[myLM startUpdatingLocation];
I've tried then to call the startUpdate method within the MyViewController class during a button event like this:

Code:
[myLocController startUpdate]
where myLocController is an object of MyLocationController. But running through the debugger the startUpdate is never called. I think a make a conceptual mistake, maybe someone could help me.
Show us your locationManager:didUpdateToLocation:fromLocation: method.

It's signature needs to be exactly correct, or it won't get called. The method name should look like this in your .m file:


- (void)locationManagerCLLocationManager *)manager didUpdateToLocationCLLocation *)newLocation fromLocationCLLocation *)oldLocation

The spelling (and case) of the method name and the names of all the parameters must match the above exactly, or it won't get called.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-24-2011, 11:09 AM   #5 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 26
petros is on a distinguished road
Default

OOOPS!!!
1st I checked this in my code and I correct it and now i call startUpdatingLocation. But I have the same problem.
2nd
The compiler does not throw an error in this line of code
didUpdateToLocationNSLocation*)newLocation
also this line of code is didUpdateToLocationCLLocation *)newLocation
and it's not a custom made method. It's a method of the location manager framework.
Thanks for yor help.
petros is offline   Reply With Quote
Old 01-24-2011, 12:13 PM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by petros View Post
OOOPS!!!
1st I checked this in my code and I correct it and now i call startUpdatingLocation. But I have the same problem.
2nd
The compiler does not throw an error in this line of code
didUpdateToLocationNSLocation*)newLocation
also this line of code is didUpdateToLocationCLLocation *)newLocation
and it's not a custom made method. It's a method of the location manager framework.
Thanks for yor help.
No, you have that wrong.

The method you need to write in order to get notified about location updates is:


Code:
- (void)locationManager: (CLLocationManager *)manager
didUpdateToLocation: (CLLocation *) newLocation 
fromLocation:(CLLocation *)oldLocation
When the location manager has a location update, it looks to see what object has been set up as it's delegate. It then looks in the delegate for the above method. It needs to be exactly that method. You can't change the names of the parameters, or the number of parameters, or their types, or it won't work.

If the location manager finds a locationManager:didUpdateToLocation:fromLocation: method in it's delegate, it calls it.

The method takes 3 parameters:

The location manager that's sending the message
The new location
The old location.

It sounds like your method only has the didUpdateToLocation part. Thus, the method will never be called.

The method locationManager:didUpdateToLocation:fromLocation: is part of the CLLocationManagerDelegate "protocol". A protocol is a defined set of messages that an object uses to communicate with another object, usually it's delegate.

If you get the method signature wrong, the method is not part of the protocol, and doesn't ever get called.

Post the full definition of your locationManager:didUpdateToLocation:fromLocation: method.

It should look exactly like this:

Code:
- (void)locationManager: (CLLocationManager *)manager
didUpdateToLocation: (CLLocation *) newLocation 
fromLocation:(CLLocation *)oldLocation
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-24-2011, 12:26 PM   #7 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 26
petros is on a distinguished road
Default

OK
And now what I have to call in button event??
petros is offline   Reply With Quote
Old 01-24-2011, 01:39 PM   #8 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by petros View Post
OK
And now what I have to call in button event??
I don't know, what do you want clicking a button to do?

The location manager is asynchronous. You ask it for updates, and it calls you "from time to time" with updates.

When you first ask for location updates, nothing happens. It takes the GPS a few seconds to get it's first reading, then it starts sending updates as the GPS reports changes in the user's location.

If you want to show the user's location instantly when he/she clicks a button, you should create a location manager and ask for updates as soon as your app launches, and save the location information as it comes in. Then, when the user clicks the "show my location" button, you can use the saved location information from the last reading to show the user's location.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-26-2011, 10:34 AM   #9 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 26
petros is on a distinguished road
Default Timer

Hi
Do you know how i can get user's current location with a timer?
petros is offline   Reply With Quote
Old 01-26-2011, 10:45 AM   #10 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by petros View Post
Hi
Do you know how i can get user's current location with a timer?
You can't.

The GPS reports location updates when it gets them. It's asynchronous, and generates updates based on the settings you used for the location manager, the quality of the signal from the GPS satellites, how fast the user is moving, and various other factors that are outside of the program's control.

What you have to do is to write a locationManager:didUpdateToLocation:fromLocation: method that receives location updates as they occur. Save the location information away, and then in your code, when you need the user's current location, look at the last location information you saved in locationManager:didUpdateToLocation:fromLocation:
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 357
9 members and 348 guests
akphyo, blueorb, fredidf, iAppDeveloper, iGamesDev, Kirkout, MarkC, mottdog, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:27 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0