多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

中國最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2

ios教程

iOS定位操作

閱讀 (1991)

IOS定位操作


簡介

在IOS中通過CoreLocation定位,可以獲取到用戶當前位置,同時能得到裝置移動信息。

實例步驟

1、創建一個簡單的View based application(視圖應用程序)。

2、擇項目文件,然后選擇目標,然后添加CoreLocation.framework,如下所示

CoreLocation_Library_Addition

3、在ViewController.xib中添加兩個標簽,創建ibOutlet名為latitudeLabel和longtitudeLabel的標簽

4、現在通過選擇" File-> New -> File... -> "選擇Objective C class 并單擊下一步

5、把"sub class of"作為NSObject,將類命名為LocationHandler

6、選擇創建

7、更新LocationHandler.h,如下所示

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

@protocol LocationHandlerDelegate <NSObject>

@required
-(void) didUpdateToLocation:(CLLocation*)newLocation 
 fromLocation:(CLLocation*)oldLocation;
@end

@interface LocationHandler : NSObject<CLLocationManagerDelegate>
{
    CLLocationManager *locationManager;
}
@property(nonatomic,strong) id<LocationHandlerDelegate> delegate;

+(id)getSharedInstance;
-(void)startUpdating;
-(void) stopUpdating;

@end

8、更新LocationHandler.m,如下所示

#import "LocationHandler.h"
static LocationHandler *DefaultManager = nil;

@interface LocationHandler()

-(void)initiate;

@end

@implementation LocationHandler

+(id)getSharedInstance{
    if (!DefaultManager) {
        DefaultManager = [[self allocWithZone:NULL]init];
        [DefaultManager initiate];
    }
    return DefaultManager;
}
-(void)initiate{
    locationManager = [[CLLocationManager alloc]init];
    locationManager.delegate = self;
}

-(void)startUpdating{
    [locationManager startUpdatingLocation];
}

-(void) stopUpdating{
    [locationManager stopUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:
 (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    if ([self.delegate respondsToSelector:@selector
    (didUpdateToLocation:fromLocation:)]) 
    {
        [self.delegate didUpdateToLocation:oldLocation 
        fromLocation:newLocation];

    }
}

@end

9、更新ViewController.h,如下所示

#import <UIKit/UIKit.h>
#import "LocationHandler.h"
@interface ViewController : UIViewController<LocationHandlerDelegate>
{
    IBOutlet UILabel *latitudeLabel;
    IBOutlet UILabel *longitudeLabel;
}
@end

10、更新ViewController.m,如下所示

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[LocationHandler getSharedInstance]setDelegate:self];
    [[LocationHandler getSharedInstance]startUpdating];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)didUpdateToLocation:(CLLocation *)newLocation 
 fromLocation:(CLLocation *)oldLocation{
    [latitudeLabel setText:[NSString stringWithFormat:
    @"Latitude: %f",newLocation.coordinate.latitude]];
    [longitudeLabel setText:[NSString stringWithFormat:
    @"Longitude: %f",newLocation.coordinate.longitude]];

}

@end

輸出

當我們運行該應用程序,會得到如下的輸出:

locationOutput

關閉
程序員人生
主站蜘蛛池模板: 欧美成人免费观看国产 | 一二三四观看视频中文在线观看 | 性生活国产| 一区二区成人国产精品 | 国产亚洲精品美女一区二区 | 五月婷婷在线免费观看 | 亚洲精品视频免费观看 | 午夜在线影院 | 国产中文字幕在线免费观看 | 亚洲一区二区三区91 | α片毛片免费看 | 久久手机看片 | 久久99久久99精品免观看麻豆 | free性欧美人另类 | 欧美3d怪物交 | 亚洲伊人99综合网 | 国产麻豆剧看黄在线观看 | 在线天堂在线 | 福利国产 | 久久久久久综合一区中文字幕 | 一区二区高清视频 | a集毛片 | 亚洲免费网站观看视频 | 五月香婷婷 | 天堂69亚洲精品中文字幕 | 国产精美视频 | 2022国产成人精彩在线视频 | 日本aa在线 | 免费视频中文字幕 | 亚洲图片校园另激情类小说 | 国产不卡视频一区二区在线观看 | 欧美一区二区影院 | 亚洲三级视频在线观看 | 欧美男男激情videos高清不卡 | 免费一级淫片aaa片毛片a级 | 国产成人福利在线 | free性欧美精品videos | 国产一区二区三区不卡观 | 欧美在线一区二区三区不卡 | 免费大片在线观看www | 国产福利在线免费观看 |