日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

中國最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2

ios教程

iOS定位操作

閱讀 (1995)

IOS定位操作


簡介

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

實例步驟

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

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

CoreLocation_Library_Addition

3、在ViewController.xib中添加兩個標(biāo)簽,創(chuàng)建ibOutlet名為latitudeLabel和longtitudeLabel的標(biāo)簽

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

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

6、選擇創(chuàng)建

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

輸出

當(dāng)我們運行該應(yīng)用程序,會得到如下的輸出:

locationOutput

關(guān)閉
程序員人生
主站蜘蛛池模板: 国产视频污 | 狠狠色伊人亚洲综合成人 | 91玖玖| 午夜网址 | 欧美精品在线免费观看 | 国产毛片精品 | 欧美视频网 | 久久成人在线 | xxxx性欧美 | 久久韩日 | 伊人天堂网 | 欧美aa| 国产精品久久一区二区三区动漫 | 亚洲综合影院 | 日韩欧美国产一区二区 | 三级网站免费播放 | 国产一区二区免费看 | 欧美日本韩国一区二区三区 | a√天堂中文字幕 | 久久久人成影片一区二区三区 | 激情久久av一区av二区av三区 | 91精品国产欧美一区二区成人 | 成人免费观看在线 | 成人免费视频在线观看 | 黄色网页在线看 | 久久国产日韩 | 欧美福利网站 | 日韩亚洲一区二区 | 性欧美亚洲xxxx乳在线观看 | 国产成人在线观看免费网站 | 综合av在线 | 国产精选视频 | 免费在线看黄网站 | 日本成人免费在线 | 国产区精品视频 | 欧美日韩一区三区 | 欧美日韩国产三区 | 国产成人欧美一区二区三区八 | 久热国产精品 | 99精品久久99久久久久 | 在线看的毛片 |