URGENT : Get the current location

Discussion in 'iOS Programming' started by sid.bond.86, Oct 8, 2010.

  1. sid.bond.86 macrumors newbie

    Joined:
    Oct 8, 2010
    #1
    Hi,

    I am writing a simple program for iphone, in which i just need to get the current location and put it in the label.

    Now , I just want the current location and not the update location function.
    I just need to poll the GPS coordinates and print it in a label. I do not want to use the didUpdateToLocation function. I want to get the lat/long at one instance and print it.

    Please help!

    Sid
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    What you want cannot be done. It takes some time for the GPS to get a fix on the current location. So you must start it off and wait for callbacks in didUpdateToLocation.
     
  3. sid.bond.86 thread starter macrumors newbie

    Joined:
    Oct 8, 2010
    #3
    hey robbie,
    thanks for the quick response.

    Hmm.. if this is not possible, is there an y way that i can call this update function every 1 sec.

    So basically what my goal is to print the current location of a iphone every second on the screen, even if the location of the iphone has not changed.

    Please guide me as to how i can achieve this.

    Sid
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Then simply have a variable that holds the current/last reported position. Every time didUpdateToLocation is called then update the variable. Pretty simply really.
     
  5. sid.bond.86 thread starter macrumors newbie

    Joined:
    Oct 8, 2010
    #5
    Hmmm... thnks.. let me try it..
    actually this is my first iphone program.
    so i am having hard time figuring it out :(
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    How comfortable are you with the basic fundamentals of iPhone / Objective-C development?
     
  7. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #7
    Create an class object that updates its state using didUpdateToLocation.

    Then when you want to update your label (every second), just send a query message to that object to get the last state update.
     
  8. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #8
    Just FYI: didUpdateToLocation is called once per second in iOS 4* (whether or not the phone is in motion).

    * In previous iOS versions the update frequency was not so regular.
     

Share This Page