Core Location Example

Discussion in 'iPhone/iPad Programming' started by orangebeard78, Mar 17, 2008.

  1. macrumors newbie

    #1
    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 
     
  2. macrumors 68040

    #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.
     
  3. macrumors newbie

    #3
    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. macrumors newbie

    #4
    init?

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

    Chris
     
  5. macrumors regular

    #5
    Core location does not work in the simulator, you need to attach the iphone to test it.
     
  6. macrumors newbie

    #6
    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. macrumors 68040

    #7
    That is correct.
     
  8. macrumors regular

    #8
    Yup, I have the access to 2.0, but I havent gotten around to experiment with core location yet...
     
  9. macrumors newbie

    #9
    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
     
  10. macrumors newbie

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

    #11
    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..
     
  12. macrumors newbie

    #12
    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. macrumors newbie

    #13
    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. macrumors G5

    gnasher729

    #14
    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. macrumors 6502a

    #15
    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. macrumors 6502a

    Palad1

    #16
    First rule of iPhone SDK...
     
  17. Moderator

    robbieduncan

    Staff Member

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

Share This Page