0

I m working to get the Longitude and Latitude for current place and i m using the code

locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
    [locationManager startUpdatingLocation];

    - (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation{
    int degrees = newLocation.coordinate.latitude;
    double decimal = fabs(newLocation.coordinate.latitude - degrees);
    int minutes = decimal * 60;
    double seconds = decimal * 3600 - minutes * 60;
    lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
                     degrees, minutes, seconds];
    NSLog(@" Current Latitude : %@",lat);

    degrees = newLocation.coordinate.longitude;
    decimal = fabs(newLocation.coordinate.longitude - degrees);
    minutes = decimal * 60;
    seconds = decimal * 3600 - minutes * 60;
  //  longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
                //       degrees, minutes, seconds];

    longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
             degrees, minutes, seconds];
    NSLog(@" Current Longitude : %@",longt);

}

and getting the:

Current Latitude : 37° 47' 9.0024" Current Longitude : -122° 24' 23.1012"

But i want the Latitude and Longitude like that 13.233233 (mean in points). So how i can convert this in Longitude and Latitude in point ?Please help.

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • What exactly do you mean by "points"? – Onato May 29 '14 at 12:56
  • Mean in cartesian coordinates. – Jagbeer Singh May 29 '14 at 13:01
  • In Cartesian coordinates of what coordinate system? The UIView or the MKMapView? What's the purpose? If you just want to display them in decimal format, do `NSLog(@"lat,long = %f,%f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);`. Also, this is not an "android-mapview". –  May 29 '14 at 13:11

3 Answers3

0

why are you using this depreciated method use this method for getting location in iOS 7. Use this method

 -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

    {
   // location_updated = [locations lastObject];    
   // NSLog(@"updated coordinate are %@",location_updated);

    float currentLocationLati = [[locations objectAtIndex:0] coordinate].latitude;
        float currentLocationLong = [[locations objectAtIndex:0] coordinate].longitude;

    }

By this methods you will find update latitude and longitude just use them don't convert them into degree

Gajendra Rawat
  • 3,673
  • 2
  • 19
  • 36
0

From the following answer Converting from longitude\latitude to Cartesian coordinates

x = R * cos(lat) * cos(lon)
y = R * cos(lat) * sin(lon)
z = R *sin(lat)

Where R is the approximate radius of earth (e.g. 6371KM).

Community
  • 1
  • 1
Onato
  • 9,916
  • 5
  • 46
  • 54
0

In newLocation.coordinate.latitude and newLocation.coordinate.longitude, you have the values you want, just don't convert them.

gabuh
  • 1,166
  • 8
  • 15