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.

1

7 Answers 7

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

1

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

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

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
1
  • i did the above steps but my location is null, and coordinates are 0.00000.
    – Adnan Khan
    Apr 19, 2013 at 10:43
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

4
  • i am not able to find debug-> location->custom location in xcode,
    – Adnan Khan
    Apr 18, 2013 at 12:18
  • first click on simulator device and when simulator will be showing then some options will be showing above tool bar such as iossimulator,file,edit,hardware,debug,window,help, you will click on debug and go on your process. Apr 18, 2013 at 13:04
  • is it worked or not Adnan? Apr 18, 2013 at 13:16
  • i did define but it still give me long and lat 0.0000 but getlocation return null. could you help me to return the proper location.
    – Adnan Khan
    Apr 19, 2013 at 7:58
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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.