当前位置: 首页 > news >正文

欧美斯项目签到功能,实时获取当前所在位置的经纬度

由于欧美斯项目需要签到功能,因此需要给后台传一个当前位置的经纬度,以下是获取经纬度的方法

1>导入CoreLocation.frameWork

2>引入头文件,并遵循协议

#import <CoreLocation/CoreLocation.h>

<CLLocationManagerDelegate>

3>代码

@interface YYAboutUsViewController ()<UIWebViewDelegate,CLLocationManagerDelegate>

{
    UIWebView *_webView;
    NSString * _currentLatitude;  //当前位置的纬度
    NSString * _currentLongitude; //当前位置的经度
    CLLocationManager *_locManager;
    
}

@end

@implementation YYAboutUsViewController

- (void)viewWillAppear:(BOOL)animated
{
    //实例化一个位置管理器
    _locManager = [[CLLocationManager alloc] init];
    _locManager.delegate = self;
   // 设置定位精度
    // kCLLocationAccuracyNearestTenMeters:精度10米
    // kCLLocationAccuracyHundredMeters:精度100 米
    // kCLLocationAccuracyKilometer:精度1000 米
    // kCLLocationAccuracyThreeKilometers:精度3000米
    // kCLLocationAccuracyBest:设备使用电池供电时候最高的精度
    // kCLLocationAccuracyBestForNavigation:导航情况下最高精度,一般要有外接电源时才能使用
    _locManager.desiredAccuracy = kCLLocationAccuracyBest;

    // distanceFilter是距离过滤器,为了减少对定位装置的轮询次数,位置的改变不会每次都去通知委托,而是在移动了足够的距离时才通知委托程序
    // 它的单位是米,这里设置为至少移动1000再通知委托处理更新;
    _locManager.distanceFilter = 1000.0f;  // 如果设为kCLDistanceFilterNone,则每秒更新一次;
    
    //判断手机定位是否开启
    // 开启定位:设置 > 隐私 > 位置 > 定位服务
    if ([CLLocationManager locationServicesEnabled]) {
       // 启动位置更新
        // 开启位置更新需要与服务器进行轮询所以会比较耗电,在不需要时用stopUpdatingLocation方法关闭;
        [_locManager startUpdatingLocation];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"请开启定位" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
    }

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"guanyu_nav"] forBarMetrics:UIBarMetricsDefault];
    
    
    
    
    if (Device_Is_IPhone5) {
        _webView =[[UIWebView alloc]initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64)];
    }else{
        _webView =[[UIWebView alloc]initWithFrame:CGRectMake(0, 44, self.view.bounds.size.width, self.view.bounds.size.height - 44)];
    }
    [self.view addSubview:_webView];

}

#pragma mark -CLLocationManagerDelegate
// 地理位置发生改变时触发
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    // 获取经纬度
    NSLog(@"纬度:%f",newLocation.coordinate.latitude);
    NSLog(@"经度:%f",newLocation.coordinate.longitude);
    
    
    //加载网络数据
    _webView.delegate = self;
    //aboutOMS.html
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@?latitude=%f&longitude=%f",kBaseUrl,@"7.aspx",newLocation.coordinate.latitude,newLocation.coordinate.longitude]];
    NSURLRequest *request=[NSURLRequest requestWithURL:url];
    [_webView loadRequest:request];

    // 停止位置更新
    [manager stopUpdatingLocation];
}
#pragma mark -webView的代理方法-
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    return YES;
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [MBProgressHUD showWithText:@"加载中..." toView:self.view];
    
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}

@end

 

转载于:https://www.cnblogs.com/yuanyuandachao/p/3880278.html

相关文章:

  • 云原生的浪潮下,为什么运维人员适合学习Go语言?
  • HDU 2122 Ice_cream’s world III
  • 九、IIC驱动原理分析
  • mongodb安装
  • H5(WebView)跳Native(UIView)
  • poj 2888 Magic Bracelet
  • 导入【 http://ip.qq.com/js/geo.js】外部省市县三级地区到Mysql数据库
  • 前端代码风格自动化系列(二)之Commitlint
  • SharePoint 2013 Designer 入门教程
  • SparkStreaming的实战案例
  • const let
  • 冷启动问题:如何构建你的机器学习组合?
  • hive报错 Another instance of Derby may have already booted the database
  • iOS应用审核的通关秘籍【转】
  • QTP常用功能
  • 【附node操作实例】redis简明入门系列—字符串类型
  • AHK 中 = 和 == 等比较运算符的用法
  • create-react-app项目添加less配置
  • HTTP请求重发
  • JAVA 学习IO流
  • Joomla 2.x, 3.x useful code cheatsheet
  • MySQL-事务管理(基础)
  • PHP变量
  • QQ浏览器x5内核的兼容性问题
  • Storybook 5.0正式发布:有史以来变化最大的版本\n
  • 漫谈开发设计中的一些“原则”及“设计哲学”
  • 前端性能优化——回流与重绘
  • 使用阿里云发布分布式网站,开发时候应该注意什么?
  • 微信端页面使用-webkit-box和绝对定位时,元素上移的问题
  • 用quicker-worker.js轻松跑一个大数据遍历
  • 原生js练习题---第五课
  • 远离DoS攻击 Windows Server 2016发布DNS政策
  • 在weex里面使用chart图表
  • 这几个编码小技巧将令你 PHP 代码更加简洁
  • 正则表达式
  • #我与Java虚拟机的故事#连载03:面试过的百度,滴滴,快手都问了这些问题
  • #我与Java虚拟机的故事#连载16:打开Java世界大门的钥匙
  • (1)(1.11) SiK Radio v2(一)
  • (ibm)Java 语言的 XPath API
  • (NO.00004)iOS实现打砖块游戏(十二):伸缩自如,我是如意金箍棒(上)!
  • (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY)讲解
  • (二)换源+apt-get基础配置+搜狗拼音
  • (二)什么是Vite——Vite 和 Webpack 区别(冷启动)
  • (十) 初识 Docker file
  • (转)IOS中获取各种文件的目录路径的方法
  • (转)Linux整合apache和tomcat构建Web服务器
  • (最全解法)输入一个整数,输出该数二进制表示中1的个数。
  • *p++,*(p++),*++p,(*p)++区别?
  • ... 是什么 ?... 有什么用处?
  • .NET core 自定义过滤器 Filter 实现webapi RestFul 统一接口数据返回格式
  • .NET 设计模式—简单工厂(Simple Factory Pattern)
  • .net程序集学习心得
  • @RequestMapping用法详解
  • [ 环境搭建篇 ] 安装 java 环境并配置环境变量(附 JDK1.8 安装包)
  • [100天算法】-不同路径 III(day 73)