该app为应用的功能为用iPhone 显示你现在的位置

现版本 SDK 8.4 Xcode

运行Xcode 选择 Create a new Xcode project ->Single View Application 命名 WhereAmI

(1) 点击文件夹WhereAmI -> General->Linked Frameworks and Libraries -> "+"->  搜索 CoreLocation.framework ->add

(2)  打开 ViewController.h 文件,加入下面代码

#import <UIKit/UIKit.h>

#import <CoreLocation/CoreLocation.h>

#import <CoreLocation/CLLocationManagerDelegate.h>

@interface ViewController : UIViewController <CLLocationManagerDelegate>{

IBOutlet UITextField *altitude;

IBOutlet UITextField *latitude;

IBOutlet UITextField *longitude;

CLLocationManager *locmanager;

BOOL wasFound;

}

-(IBAction)update:(id)sender;

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *) oldLocation ;

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *) error;

@end

(3)  打开 ViewController.m 文件,加入下面代码

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

-(IBAction)update:(id)sender{

locmanager = [[CLLocationManager alloc]init];

[locmanager setDelegate:self];

[locmanager setDesiredAccuracy:kCLLocationAccuracyBest];

locmanager.distanceFilter=10;

NSString *iOSVersion=[UIDevice currentDevice].systemVersion;

//NSLog(@"%@",iOSVersion);

if ((int)iOSVersion >= 8) {

[locmanager requestWhenInUseAuthorization];//使用程序其间允许访问位置数据(iOS8定位需要)

}

[locmanager startUpdatingLocation];

}

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{

if(wasFound)return;

wasFound = YES;

CLLocationCoordinate2D loc = [newLocation coordinate];

latitude.text = [NSString stringWithFormat:@"%f",loc.latitude];

longitude.text = [NSString stringWithFormat:@"%f",loc.longitude];

altitude.text = [NSString stringWithFormat:@"%f",newLocation.altitude];

}

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{

}

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

(3) 设置info.plist

点击info.plist,在右侧添加NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription

将 Value设置为YES

(4) UIView 界面设置

点击Main.storyboard

加入三个Label 在 Attributes 下, Text 内填上"经度",“纬度”,“海拔”;

加入 三个Text Field用于显示 "经度",“纬度”,“海拔”;

鼠标右击Text Field控件 移动鼠标在"Referencing Outlets" 后面圆圈上; 圆圈变为(+); 拖动直线连接到"view controller";
放开鼠标选择键出现 "longitude","latitude","altitude"; 对应着"经度",“纬度”,“海拔”三个Text Field ,分别选上它。

选择: File -> Save

最后在 xCode 选择 Build and then Running

(5)真机调试效果图

本文源于网上博客教程,经过本人修改和测试。原blog地址 http://blog.sina.com.cn/s/blog_5fae23350100e5fi.html

转载于:https://www.cnblogs.com/huaixu/p/4694902.html

四、卫星定位《苹果iOS实例编程入门教程》相关推荐

  1. IOS 初级开发入门教程(四)基础控件使用小练习

    前言 看完前面3章的内容,基本对IOS开发有一些认识了,这章我们开始动手去实践做点小练习,学习如何创建并设置标签和按钮(Label & Button)的相关属性,以及通过一个交互式的案例演示动 ...

  2. TZC Python编程入门教程 ————题解

    本博客原文地址:Python编程入门教程(以在线评测平台为载体) - 暴力都不会的蒟蒻 - 博客园,原文体验更佳 如果你是一名浙江2020级及以后的高中生要学习Python,抑或是一位科学工作者要学习 ...

  3. python全栈工程师 pdf_python全栈工程师项目开发实例实战入门教程百度云

    python全栈工程师项目开发实例实战入门教程百度云 课程目录: 开学典礼 pycharm的基本使用 Python基本语法 数值类型数据及运算 字符串的基本操作 字符串的常用方法 列表的基本使用 列表 ...

  4. 【转载】PHP面向对象(OOP)编程入门教程

    面向对象编程(OOP)是我们编程的一项基本技能,PHP5对OOP提供了良好的支持. 如何使用OOP的思想来进行PHP的高级编程,对于提高 PHP编程能力和规划好Web开发构架都是非常有意义的.下面我们 ...

  5. PHP面向对象(OOP)编程入门教程

    面向对象编程(OOP)是我们编程的一项基本技能,PHP5对OOP提供了良好的支持.如何使用OOP的思想来进行PHP的高级编程,对于提高 PHP编程能力和规划好Web开发构架都是非常有意义的.下面我们就 ...

  6. 学习嵌入式的书籍推荐,嵌入式编程入门教程学习大纲

    嵌入式系统是当前热门.具发展前景的IT应用领域之一,很多数字包括手机.电子字典.可视电话.数字相机.数字摄像机.机顶盒.智能玩具医疗仪器和航空航天设备等都是典型的嵌入式系统.越来越多的人想要了解学习嵌 ...

  7. 基于VB的COM编程入门教程

        VB COM编程教程   ⊙ 论坛热贴 用VB编写批量重命名文件问题 如何将图像填充整个表单 正则表达式中如何跳过回车符 如何让小老鼠变个样? >>>>更多... ⊙ ...

  8. VS2010/MFC编程入门教程之目录和总结

    写这套VS2010/MFC编程入门教程历时八个月,时间比较长,都是鸡啄米在工作之余加班加点完成的.虽然有点累,但看到有这么多人过来支持鸡啄米,很是值得. 写每节教程我都力求讲明白,深入浅出的阐述每个知 ...

  9. VS2010/MFC编程入门教程

    一.VS2010/MFC编程入门教程之目录       第一部分:VS2010/MFC开发环境       VS2010/MFC编程入门之前言        VS2010/MFC编程入门之一(VS20 ...

最新文章

  1. Python 开源项目 Top 10 精选(平均star为1128)
  2. 命名实体识别_用膨胀卷积进行命名实体识别 NER
  3. 【Python-ML】神经网络-深度学习库Keras
  4. cocos2dx 3.3 Director setNotificationNode BUG
  5. 提升ListView的运行效率
  6. python tensorflow pytorch 深度学习 车牌识别
  7. select点击option获取文本输入框的焦点事件
  8. 采用URL访问资源,隐藏真实地址
  9. liferay remove Your request completed successfully.
  10. 我国数据中心产业发展“渐入佳境” 服务是重中之重
  11. Unity 如何修改 particle system 的 start color 属性
  12. java反射 set_Java反射
  13. horizontalscrollview+textview简单版
  14. 《国民经济行业分类GB/T 4754—2017》官网下载地址
  15. x5webview TbsReaderView首次加载失败
  16. 2021年UI设计面试问题及答案解析
  17. 2019春 总结作业
  18. 几种公共图床Python调用
  19. 新人如何利用今日头条自媒体平台赚钱?月收入轻松过万
  20. 去除 csv 文件中的重复行

热门文章

  1. 激光光凝后容易出现频繁闪光的原因
  2. @RequestMapping和@GetMapping @PostMapping 区别
  3. lombok不生效问题(持续补充)
  4. 大话数据结构03:静态链表
  5. Java 比特币开发系列教程汇总
  6. 《Spring_four》团队作业4—基于原型的团队项目需求调研与分析
  7. SocialFish-kali下社会工程学钓鱼工具
  8. 基于casperjs、resemble.js实现一个像素对比服务
  9. BZOJ-1057: [ZJOI2007]棋盘制作(单调栈)
  10. tomcat 页面图片 管理 服务器 配置