PDA

View Full Version : Core Location Example




orangebeard78
Mar 17, 2008, 04:56 PM
Does anyone have any examples they would like to share regarding the
Core Location framework in the SDK? I am in desperate need of help.
The only code that I can find is what is available on the iPhone Dev
website, which isn't much. I tried to implement the code into my
program but I get a error: "locationManager undeclared (first use in
this funciton".

Here is the code...

#import "MyLocationGetter.h"
#import <CoreLocation/CoreLocation.h>

@implementation MyLocationGetter

- (void)startUpdates
{
// Create the location manager if this object does not
// already have one.

//ERROR is HERE!!!
if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];

locationManager.delegate = self;
locationManager.distanceFilter = 1000; // 1 kilometer
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
[locationManager startUpdatingLocation];

}

// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
// Disable future updates to save power.
[manager stopUpdatingLocation];

printf("latitude %+.6f, longitude %+.6f\n",
newLocation.coordinate.latitude,
newLocation.coordinate.longitude);

}

@end



admanimal
Mar 17, 2008, 05:01 PM
Is locationManager declared as a property of MyLocationGetter in your header file? If not, it is undeclared in the startUpdates method and that is why you are getting that error.

orangebeard78
Mar 17, 2008, 05:10 PM
thanks admanimal for the reply.

it is not declared as a property.

newbie question...what should I declare it as? and how to declare it? not real comfortable with Ojective-C yet if you couldn't already tell :)

CMoebius
Apr 1, 2008, 08:07 AM
I am struggling with getting the Core Location stuff working also. Does anyone know if it works in the emulator?

Chris

himansk
Apr 1, 2008, 10:29 AM
Core location does not work in the simulator, you need to attach the iphone to test it.

CMoebius
Apr 1, 2008, 10:10 PM
Only if you are one of the lucky ones to be accepted into the Developer Program, right? You have to have the 2.0 beta on the phone to be able to transfer apps to it, right?

admanimal
Apr 1, 2008, 11:31 PM
Only if you are one of the lucky ones to be accepted into the Developer Program, right? You have to have the 2.0 beta on the phone to be able to transfer apps to it, right?

That is correct.

himansk
Apr 2, 2008, 09:53 AM
Only if you are one of the lucky ones to be accepted into the Developer Program, right? You have to have the 2.0 beta on the phone to be able to transfer apps to it, right?

Yup, I have the access to 2.0, but I havent gotten around to experiment with core location yet...

nujjus
Apr 12, 2008, 08:35 PM
Hmm, did this work for you? For some reason I get linking errors:

"_kCLLocationAccuracyKilometer", referenced from:
_kCLLocationAccuracyKilmoeter$non_lazy_ptr in MyLocationGetter.o

and

".objc_class_name_CLLocationManager", referened from:
literal-pointer@__OBJC@__cls_refs@CLLocationManager in MyLocationGetter.o
symbol(s) not found
collect2: ld returned 1 exit status

CMoebius
Apr 13, 2008, 04:55 PM
Hmm, did this work for you? For some reason I get linking errors:

"_kCLLocationAccuracyKilometer", referenced from:
_kCLLocationAccuracyKilmoeter$non_lazy_ptr in MyLocationGetter.o

and

".objc_class_name_CLLocationManager", referened from:
literal-pointer@__OBJC@__cls_refs@CLLocationManager in MyLocationGetter.o
symbol(s) not found
collect2: ld returned 1 exit status

You have to add the core location framework to your project. If you right-click on the name of your project in the groups pane and choose add existing framework (can't remember the exact wording) it should build.

Hope this helps.

sefudiere
Apr 18, 2008, 12:50 AM
And where would this framework be located? I tried adding from /System/Library/frameworks and i could not find a CoreLocation.framework there or anything remotely close to it.

Thanks..

CMoebius
Apr 19, 2008, 03:00 PM
And where would this framework be located? I tried adding from /System/Library/frameworks and i could not find a CoreLocation.framework there or anything remotely close to it.

Thanks..

in this folder on my machine:

Macintosh HD\Developer\Platforms\iPhoneSimulator.platform\Developer\SDKs\iPhoneSimulator2.0.sdk\System\Library \Frameworks

and it's name is CoreLocation.framework

I guess you could search your machine for this filename also.

Hope this helps.

newy
Aug 24, 2008, 11:17 PM
Hmm, did this work for you? For some reason I get linking errors:

"_kCLLocationAccuracyKilometer", referenced from:
_kCLLocationAccuracyKilmoeter$non_lazy_ptr in MyLocationGetter.o

and

".objc_class_name_CLLocationManager", referened from:
literal-pointer@__OBJC@__cls_refs@CLLocationManager in MyLocationGetter.o
symbol(s) not found
collect2: ld returned 1 exit status

I am getting this same error and am SO frustrated... I've tried dragging the CoreLocation framework from the LocateMe sample and other examples that work and it still fails when I put it into my own project. How do you fix this?!!?!?

gnasher729
Aug 25, 2008, 08:19 AM
I tried to implement the code into my
program but I get a error: "locationManager undeclared (first use in
this funciton".

1. The iPhone SDK is under NDA. Anyone who publishes examples how to use any iPhone-specific Cocoa classes is in breach of their NDA, which could have all kinds of unpleasant consequences.

2. When the compiler says "xxx undeclared (first use in this function)" it means that you haven't declared xxx anywhere, at least not somewhere where the compiler could find it. This is basic Objective-C programming and has nothing to do with the iPhone at all. What is "locationManager" supposed to be? If it is supposed to be a static or global variable, then you better define it as a static or global variable.

liptonlover
Aug 25, 2008, 10:19 AM
that stupid NDA... I gave up on learning iphone specific stuff for now because of it. I believe you can use a hooked up iphone as a testing device without getting into the $99 developer license. The app just won't stay on the device.

Palad1
Aug 27, 2008, 04:19 AM
First rule of iPhone SDK...

robbieduncan
Aug 27, 2008, 04:41 AM
that stupid NDA... I gave up on learning iphone specific stuff for now because of it. I believe you can use a hooked up iphone as a testing device without getting into the $99 developer license. The app just won't stay on the device.

I believe otherwise: I certainly couldn't until I got my provisioning profile...