Detect Users Location MapKit

Discussion in 'iPhone/iPad Programming' started by Alex2k3, Mar 5, 2012.

  1. Alex2k3, Mar 5, 2012
    Last edited by a moderator: Mar 5, 2012

    macrumors newbie

    Joined:
    Mar 5, 2012
    #1
    Hello.

    I'm trying to develop my first app, a map app that shows nearby grocery stores with pins. But I have one problem, I'm not able to get the "users" location when i press the "location" button.
    I have only found tutorials with latitude and longitude, and I have changed them to my location, but when I'm another place and presses the location button, the old location appears.
    Is there any way to get the location to "autoupdate"?

    This is the code in my ViewController.m file

    Code:
    -(IBAction)getlocation {
        
        mapView.showsUserLocation = YES;
        MKCoordinateRegion region;
        region.center.latitude = 61.232357;
        region.center.longitude = 10.22526;
        region.span.longitudeDelta = 0.01;
        region.span.latitudeDelta = 0.01;
        [mapView setRegion:region animated:YES];
     
  2. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    You are allways setting your region to the same latitude and longitude, you're not getting the real time data..
    There is a delegate method for that, updateToLocation, you need to search something like that, IF a new location has found, just trigger your method..
    Something like that should be the flow.
     
  3. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
  4. macrumors 6502

    Joined:
    Jun 19, 2009
    #4
    Are you running your code on the device or in the simulator?

    To display the user's location, all you need to do is this:

    Code:
    mapView.showsUserLocation = YES;
    Provided you've set up your map view correctly, of course.

    But you need to be running on the device to really see it work.
     

Share This Page