PDA

View Full Version : Detect Users Location MapKit




Alex2k3
Mar 5, 2012, 05:39 AM
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

-(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];



jnoxx
Mar 5, 2012, 06:46 AM
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.

dejo
Mar 5, 2012, 08:18 AM
Be sure to have read the Location Awareness Programming Guide (https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/Introduction/Introduction.html).

TheWatchfulOne
Mar 5, 2012, 05:09 PM
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.