0

I am trying to get current long and lat by location but i am getting both 0.0000, the following code i am using

(CLLocationCoordinate2D) getLocation{
    CLLocationManager *locationManager = [[[CLLocationManager alloc] init] autorelease];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    [locationManager startUpdatingLocation];
    CLLocation *location = [locationManager location];
    CLLocationCoordinate2D coordinate = [location coordinate];

    return coordinate;
}

And to call it use:

CLLocationCoordinate2D coordinate = [self getLocation];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];

NSLog(@"*dLatitude : %@", latitude);
NSLog(@"*dLongitude : %@",longitude);

i also added corelocation to the project. please advise me.

Adnan Khan
  • 897
  • 5
  • 14
  • 23
  • 1
    If you want to set your current location Check this http://stackoverflow.com/questions/214416/set-the-location-in-iphone-simulator – Navnath Godse Apr 18 '13 at 12:07

7 Answers7

3

Implement delegate method of location manager

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation: (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

and you can get lat and lng using newLocation.coordinate.latitude and newLocation.coordinate.longitude

And for set current location in simulator you can follow @ios_av

chirag
  • 1,090
  • 9
  • 13
1

You have to add Custom Location using this path: Select iPhone Simulator and select Debug -->Loction --> Custom Location in menu

Prasad G
  • 6,702
  • 7
  • 42
  • 65
1

IPHone simulator always give 0.0000 for lat and long because it doesn't detect the location.

You can add Custom Location using this path: Select iPhone Simulator and select Debug -->Loction --> Custom Location

ios_av
  • 324
  • 3
  • 8
1

try this

  1. Run project in iPhone Simulator
  2. Create in TextEdit file following file, call it MyOffice for example. Make extension as .gpx enter image description here
  3. Select in Xcode at the Simulate area Add GPX File to Project...enter image description here
  4. Add created file from menu to project.
  5. Now you can see your location in Simulate area:enter image description here
0

simulator can not return current location,its gives default california latitude and longitude location,but you can set statically location in simulator by - Debug -> Location -> Custom Location

0

in simulator you can force a local position: go to menu:debug:position and chose one of the voices (some simulates movements via a preregistered route) or enter coordinates of your choice

meronix
  • 6,175
  • 1
  • 23
  • 36
0

If you want to get you current location in your app then check this tutorial
http://www.techotopia.com/index.php/An_Example_iOS_5_iPhone_Location_Application

If you are not running this on device then add your latitude and longitude for simulator
for that check this
https://stackoverflow.com/a/12637537/2106973

Community
  • 1
  • 1
Navnath Godse
  • 2,233
  • 2
  • 23
  • 32