閱讀492 返回首頁    go 阿裏雲 go 技術社區[雲棲]


獲取當前經緯度方法

首先頭文件應繼承CLLocationManagerDelegate.
並:#import <CoreLocation/CoreLocation.h>

響應事件中寫如下代碼:
CLLocationManager *_locManager = [[CLLocationManager alloc] init];
[_locManager setDelegate:self];
[_locManager setDesiredAccuracy:kCLLocationAccuracyBest];    
[_locManager startUpdatingLocation];

重載
#pragma mark -
#pragma mark Location manager
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    CLLocationCoordinate2D loc = [newLocation coordinate];
    NSString *lat =[NSString stringWithFormat:@"%f",loc.latitude];//get latitude
    NSString *lon =[NSString stringWithFormat:@"%f",loc.longitude];//get longitude    
    NSLog(@"%@ %@",lat,lon);
}

最後更新:2017-04-02 22:16:01

  上一篇:go 解決myeclipse編輯js緩慢的問題
  下一篇:go Android:ScrollView/HorizontalScrollView常用技巧