how to get GPS Coordinates in iphone using Objective C

后端 未结 4 1129
暗喜
暗喜 2021-02-04 22:33

i want to get the GPS coordinates from iphone and send these GPS coordinates to web service. This web service, will take my GPS Coordinates and send me the location of the near

4条回答
  •  甜味超标
    2021-02-04 23:14

    Import CoreLocation framework to app

    import CoreLocation/CoreLocation.h librarie to ViewController

    edit ViewController header file

    #import 
    #import 
    
    @interface EMViewController : UIViewController {
        CLLocationManager *locationManager;
    }
    @end
    

    initialize locationManager in ViewController implementation

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        locationManager = [[CLLocationManager alloc] init];
    
        [locationManager startUpdatingLocation];
        NSLog(@" lat: %f",locationManager.location.coordinate.latitude);
        NSLog(@" lon: %f",locationManager.location.coordinate.longitude);
    
        [locationManager stopUpdatingLocation];
    }
    

提交回复
热议问题