Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

orangebeard78

macrumors newbie
Original poster
Mar 17, 2008
2
0
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...
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

macrumors 68040
Apr 22, 2005
3,531
2
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

macrumors newbie
Original poster
Mar 17, 2008
2
0
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 :)
 

himansk

macrumors regular
Oct 16, 2006
222
1
Core location does not work in the simulator, you need to attach the iphone to test it.
 

CMoebius

macrumors newbie
Apr 1, 2008
8
0
Tampa Bay, FL
Attach an iPhone?

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?
 

himansk

macrumors regular
Oct 16, 2006
222
1
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

macrumors newbie
Apr 12, 2008
8
0
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

macrumors newbie
Apr 1, 2008
8
0
Tampa Bay, FL
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

macrumors newbie
Oct 23, 2007
5
0
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

macrumors newbie
Apr 1, 2008
8
0
Tampa Bay, FL
The core location framework is...

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

macrumors newbie
Aug 24, 2008
2
0
CoreLocation linking error

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

Suspended
Nov 25, 2005
17,980
5,566
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

macrumors 6502a
Mar 13, 2008
989
0
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.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.