Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get GPS coordinate debugging with simulator in iOS?

I try to get coordinate of my location.

I stackoverflowed so what I coded is below:

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
[locationManager startUpdatingLocation];

CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];

self.longitude=coordinate.longitude;
self.latitude=coordinate.latitude;

NSLog(@"dLongitude : %f",self.longitude);
NSLog(@"dLatitude : %f", self.latitude);

But I'm always getting 0 all the time. Is the code above wrong? or I didn't set my simulator for GPS location?

I don't understand why I'm having trouble in getting coordinate.

like image 551
LKM Avatar asked Mar 16 '23 19:03

LKM


1 Answers

Firstly, here are several issues in your code:

  1. You should retain locationManager somewhere to keep it running
  2. Implement -locationManager:didUpdateLocations: and -locationManager:didFailWithError: delegate methods
  3. Also, if you are in iOS 8, you should add [locationMamager requestWhenInUseAuthorization]; or [locationMamager requestAlwaysAuthorization];
  4. Specify NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription accordingly in your Info.plist

You can simulate location using Xcode, look at the information from Apple: https://developer.apple.com/library/ios/recipes/xcode_help-debugger/articles/simulating_locations.html

like image 131
Azat Avatar answered Apr 26 '23 07:04

Azat