iphone ipad 显示当前城市名称

iphone ipad 显示当前城市名称,第1张

概述利用 iPhone、iPad 自带的 GPS 信息可以获得当前位置坐标,但直接高速用户坐标是不行的。CocoaChina 会员"laigb"分享了通过 GPS 信息获取当前所在城市名的代码,希望对苹果开发者有所帮助。 //  testLocationViewController.m //作者:禚来强 iphone开发*****:79190809 邮箱:zhuolaiqiang@gmail.com 利用 iPhone、iPad 自带的 GPS 信息可以获得当前位置坐标,但直接高速用户坐标是不行的。CocoaChina 会员"laigb"分享了通过 GPS 信息获取当前所在城市名的代码,希望对苹果开发者有所帮助。
//  testLocationVIEwController.m
//作者:禚来强 iphone开发*****:79190809 邮箱:zhuolaiqiang@gmail.com //  testLocation // //  Created by laiqiang zhuo on 5/11/11. //  copyright 2011 mtime. All rights reserved. // #import "testLocationVIEwController.h" @implementation testLocationVIEwController @synthesize locationmanger = _locationmanger; - (voID)dealloc {     [super dealloc];     [_locationmanger release]; } #pragma mark - VIEw lifecycle // Implement vIEwDIDLoad to do additional setup after loading the vIEw,typically from a nib. - (voID)vIEwDIDLoad {     [super vIEwDIDLoad];     cityLabel = [[[UILabel alloc] initWithFrame: CGRectMake(20,30,100,100)] autorelease];     [self.vIEw addSubvIEw: cityLabel];     /*     self.locationmanger = [[CLLocationManager alloc] init];     _locationmanger.delegate = self;     _locationmanger.desiredAccuracy = kCLLocationAccuracyBest;     [_locationmanger startUpdatingLocation];      */     _locationmanger = [[CLLocationManager alloc] init];     _locationmanger.delegate = self;     _locationmanger.distanceFilter = 1;     _locationmanger.desiredAccuracy = kCLLocationAccuracyBest;     [_locationmanger startUpdatingLocation]; } - (voID)vIEwDIDUnload {     [super vIEwDIDUnload];     // Release any retained subvIEws of the main vIEw.     // e.g. self.myOutlet = nil; } - (BOol)shouldautorotatetoInterfaceOrIEntation:(UIInterfaceOrIEntation)interfaceOrIEntation {     // Return YES for supported orIEntations     return YES; } - (voID)locationManager:(CLLocationManager *)manager        dIDFailWithError:(NSError *)error { } - (voID)locationManager:(CLLocationManager *)manager dIDUpdatetoLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {     CLLocationdistance l = newLocation.coordinate.latitude;//得到经度     CLLocationdistance v = newLocation.coordinate.longitude;//得到纬度     NSLog(@"%f %f",l,v);     CLLocation *new = [[CLLocation alloc] initWithLatitude: 11.0 longitude: 12.0];     CLLocationdistance u = [newLocation distanceFromLocation: new];     NSLog(@"%f",u);     [self startedReverseGeoderWithLatitude: l longitude: v]; } - (voID)startedReverseGeoderWithLatitude:(double)latitude longitude:(double)longitude{     CLLocationCoordinate2D coordinate2D;     coordinate2D.longitude = longitude;     coordinate2D.latitude = latitude;     MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate2D];     geoCoder.delegate = self;     [geoCoder start]; } #pragma mark - - (voID)reverseGeocoder:(MKReverseGeocoder *)geocoder dIDFindplacemark:(MKPlacemark *)placemark {     Nsstring *subthroung=placemark.subThoroughfare;     Nsstring *local=placemark.locality;     NSLog(@"城市名:%@-%@-%@",placemark.locality,local,subthroung);     if (local) {        [cityLabel setText:local];     } } - (voID)reverseGeocoder:(MKReverseGeocoder *)geocoder dIDFailWithError:(NSError *)error { } @end
总结

以上是内存溢出为你收集整理的iphone ipad 显示当前城市名称全部内容,希望文章能够帮你解决iphone ipad 显示当前城市名称所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1089634.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存