Detect Users Location MapKit

Discussion in 'iOS Programming' started by Alex2k3, Mar 5, 2012.

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

    Alex2k3 macrumors newbie

    Mar 5, 2012

    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

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


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    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. TheWatchfulOne macrumors 6502


    Jun 19, 2009
    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:

    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