日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/19 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 四、卫星定位《苹果iOS实例编程入门教程》 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

該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实例编程入门教程》的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。