Core Location Example

Discussion in 'iOS Programming' started by orangebeard78, Mar 17, 2008.

  1. orangebeard78 macrumors newbie

    Mar 17, 2008
    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",
  2. admanimal macrumors 68040

    Apr 22, 2005
    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.
  3. orangebeard78 thread starter macrumors newbie

    Mar 17, 2008
    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 :)
  4. CMoebius macrumors newbie

    Apr 1, 2008
    Tampa Bay, FL

    I am struggling with getting the Core Location stuff working also. Does anyone know if it works in the emulator?

  5. himansk macrumors regular

    Oct 16, 2006
    Core location does not work in the simulator, you need to attach the iphone to test it.
  6. CMoebius macrumors newbie

    Apr 1, 2008
    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?
  7. admanimal macrumors 68040

    Apr 22, 2005
    That is correct.
  8. himansk macrumors regular

    Oct 16, 2006
    Yup, I have the access to 2.0, but I havent gotten around to experiment with core location yet...
  9. nujjus macrumors newbie

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

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


    ".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
  10. CMoebius macrumors newbie

    Apr 1, 2008
    Tampa Bay, FL
    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.
  11. sefudiere macrumors newbie

    Oct 23, 2007
    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.

  12. CMoebius macrumors newbie

    Apr 1, 2008
    Tampa Bay, FL
    The core location framework is...

    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.
  13. newy macrumors newbie

    Aug 24, 2008
    CoreLocation linking error

    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?!!?!?
  14. gnasher729 macrumors P6


    Nov 25, 2005
    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.
  15. liptonlover macrumors 6502a

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


    Feb 24, 2004
    London, UK
  17. robbieduncan Moderator emeritus


    Jul 24, 2002
    I believe otherwise: I certainly couldn't until I got my provisioning profile...

Share This Page