IOS開発インスタンス-ユーザーの現在の地理的座標の取得


法一:高徳地図を使用する場合、代理方法があります.
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
この方法で書く
double gps_lat = userLocation.coordinate.latitude;
double gps_lng = userLocation.coordinate.longitude;
法二:転自http://www.2cto.com/kf/201402/279078.html
1.CoreLocationをインポートする.frameWork
2.CLLocationManagerクラスから位置情報を取得する# import "TestViewController.h"
  @implementation TestViewController
  #pragma mark - view life cycle - ( void )viewDidLoad {      [ super viewDidLoad];      //      self.locationManager = [[CLLocationManager alloc] init];      self.locationManager.delegate = self;             //      // kCLLocationAccuracyNearestTenMeters: 10      // kCLLocationAccuracyHundredMeters: 100      // kCLLocationAccuracyKilometer: 1000      // kCLLocationAccuracyThreeKilometers: 3000      // kCLLocationAccuracyBest:      // kCLLocationAccuracyBestForNavigation: ,      self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;             // distanceFilter , , ,      // , 1000 ;      self.locationManager.distanceFilter = 1000 .0f; // kCLDistanceFilterNone, ;        } #pragma mark - Actions - (IBAction)buttonClicked:(id)sender {      //      // : > > >      if ([CLLocationManager locationServicesEnabled]) {          //          // , stopUpdatingLocation ;          [self.locationManager startUpdatingLocation];      }      else {          NSLog(@ " !" );      }
    }
//地理的位置が変更されたときにエージェントをトリガーする方法- ( void )locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {      //      NSLog(@ " :%f" ,newLocation.coordinate.latitude);      NSLog(@ " :%f" ,newLocation.coordinate.longitude);      //      [manager stopUpdatingLocation]; } // - ( void )locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {      NSLog(@ "error:%@" ,error); }