企业信息

    北京沃赢科技有限公司

  • 12
  • 公司认证: 营业执照已认证
  • 企业性质:
    成立时间:
  • 公司地址: 北京市 海淀区 海淀街道 北京市海淀区银海大厦
  • 姓名: 刘老师
  • 认证: 手机未认证 身份证未认证 微信未绑定

    IOS定位操作

  • 所属行业:商务服务 教育培训 管理培训
  • 发布日期:2015-07-28
  • 阅读量:180
  • 价格:面议
  • 产品规格:不限
  • 产品数量:10000.00 件
  • 包装说明:不限
  • 发货地址:北京海淀海淀  
  • 关键词:在线教育,我赢职场

    IOS定位操作详细内容

    IOS定位操作
    
    简介
    在IOS中通过CoreLocation定位,可以获取到用户当前位置,同时能得到装置移动信息。
    实例步骤
    1、创建一个简单的View based application(视图应用程序)。
    2、择项目文件,然后选择目标,然后添加CoreLocation.framework,如下所示
    
    3、在ViewController.xib中添加两个标签,创建ibOutlet名为latitudeLabel和longtitudeLabel的标签
    4、现在通过选择" File-> New -> File... -> "选择Objective C class 并单击下一步
    5、把"sub class of"作为NSObject,将类命名为LocationHandler
    6、选择创建
    7、更新LocationHandler.h,如下所示
    #import 
    #import 
    @protocol LocationHandlerDelegate 
    @required
    -(void) didUpdateToLocation:(CLLocation*)newLocation
      fromLocation:(CLLocation*)oldLocation;
    @end
    @interface LocationHandler : NSObject{
        CLLocationManager *locationManager;}@property(nonatomic,strong)
     id
     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 
    #import "LocationHandler.h"
    @interface ViewController : UIViewController{
        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
    学习链接/ios/?tg=5009295340
    学习交流群:317140762
    

    http://jiexiaotan.cn.b2b168.com
    欢迎来到北京沃赢科技有限公司网站, 具体地址是北京市海淀区海淀街道北京市海淀区银海大厦,联系人是刘老师。 主要经营iOS开发、互联网架构师、安卓、Oracle、SAP、RedHat等。 单位注册资金未知。 我们公司主要服务有:教育教学软件等,我们愿以优质的服务和诚意、为您提供精良的产品和专业枝术,共创美好未来!