Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Alex2k3

macrumors newbie
Original poster
Mar 5, 2012
3
0
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];
 
Last edited by a moderator:
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.