需要实现代理CLLocationManagerDelegate,MKReverseGeocoderDelegate
并导入CoreLocation 框架。
代理使用方法 如下:
#pragma mark – 获取城市名称
// iso 5.0 以下版本使用此方法
- (void)startedReverseGeoderWithLatitude:(double)latitude longitude:(double)longitude{
CLLocationCoordinate2D coordinate2D;
coordinate2D.longitude = longitude;
coordinate2D.latitude = latitude;
MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinate2D];
self.reverseGeocoder = geoCoder;
[geoCoder release];
self.reverseGeocoder.delegate = self;
[self.reverseGeocoder start];
}
#pragma mark –
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
NSString *thoroughfare=placemark.thoroughfare;
if (thoroughfare) {
self.locationLabel.text = thoroughfare;
}
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
NSLog(@”获取失败”);
}
// IOS 5.0 及以上版本使用此方法
- (void)locationAddressWithLocation:(CLLocation *)locationGps
{
CLGeocoder *clGeoCoder = [[CLGeocoder alloc] init];
self.geoCoder = clGeoCoder;
[clGeoCoder release];
[self.geoCoder reverseGeocodeLocation:locationGps completionHandler:^(NSArray *placemarks, NSError *error)
{
NSLog(@"error %@ placemarks count %d",error.localizedDescription,placemarks.count);
for (CLPlacemark *placeMark in placemarks)
{
NSLog(@"地址:%@",placeMark.locality);
NSLog(@"地址:%@",placeMark.thoroughfare);
NSLog(@"地址:%@",placeMark.subLocality);
self.locationLabel.text = placeMark.thoroughfare;
}
}];
}
#pragma mark – location Delegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@”定位出错”);
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
if (!newLocation) {
[self locationManager:manager didFailWithError:(NSError *)NULL];
return;
}
if (signbit(newLocation.horizontalAccuracy)) {
[self locationManager:manager didFailWithError:(NSError *)NULL];
return;
}
[manager stopUpdatingLocation];
NSLog(@”%f,%f”,newLocation.coordinate.latitude,newLocation.coordinate.longitude);
_coordinate.latitude = newLocation.coordinate.latitude;
_coordinate.longitude = newLocation.coordinate.longitude;
self.gpsLabel.text = [NSString stringWithFormat:@"%f,%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude];
//解析并获取当前坐标对应得地址信息
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
[self locationAddressWithLocation:newLocation];
}else {
[self startedReverseGeoderWithLatitude:newLocation.coordinate.latitude
longitude:newLocation.coordinate.longitude];
}
}
转自:http://redstar.easymorse.com/?p=349
分享到:
相关推荐
资源名称:Cocos2d-x实战:JS卷——Cocos2d-JS开发内容简介:本书是介绍Cocos2d-x游戏编程和开发技术书籍,介绍了使用Cocos2d-JS中核心类、瓦片地图、物理引擎、音乐音效、数据持久化、网络通信、性能优化、多平台...
Cocos2d-x是移动跨平台开发最流行的游戏引擎,而本书是一本很全面的、比较‘接地气’的游戏开发教程。书中汇聚了热门手机游戏《捕鱼达人》开发的实战经验,作者从最基础的内容开始,逐步深入地介绍了Cocos2d-x的相关...
此书包含了cocos2d开发的基础知识,适合初学者上手。
资源名称:Cocos2D-X游戏开发技术精解内容简介:Cocos2D-X是一款支持多平台的 2D手机游戏引擎,支持iOS、Android、BlackBerry等众多平台。当前,很多移动平台流行的游戏,都是基于Cocos2D-X开发的。 《Cocos2D-X...
《Cocos2D-X游戏开发技术精解》详细介绍如何使用Cocos2D-X引擎开发自己的移动平台游戏。全书共15章,主要内容包括:Cocos2D-X引擎简介;如何建立跨平台的开发环境;引擎的核心模块——渲染框架;如何实现动态画面和...
本书根据大富翁项目一一展开讲解游戏开发过程中涉及的各方面内容,读者可以通过这个游戏的开发,全面掌握Cocos2d-x游戏开发的方法和技巧。 本书理论和实践相结合, 资源太大,传百度网盘了,链接在附件中,有需要的...
Cocos2d-x实战 JS卷 Cocos2d-JS开发 PDF 电子书完整版本
cocos2d案例,一个比较小的小游戏,可以查看案例了解cocos2d开发。
精通COCOS2D-X游戏开发 精通COCOS2D-X游戏开发 精通COCOS2D-X游戏开发 精通COCOS2D-X游戏开发 精通COCOS2D-X游戏开发
Cocos2d-x源于Cocos2d,是一款开源游戏引擎项目,是一款基于对原有iOS平台cocos2d重写为C++的开源代码,封装了OpenGL,Box2d,LibCurl,LibPng等开源的跨平台代码。由于基于C++和STL特点使其广泛应用于游戏开发、移动...
第1章 开始前的准备工作 1 第2章 你的第一款iPhone游戏:垂直射击游戏 38 第3章 Cocos2D核心类 69 第4章 Cocos2D中的动作、特效与动画 152 第5章 Cocos2D中的文本渲染系统 229 共19章
该书作者是《保卫萝卜》核心开发人员,该书手把手教会大家如何使用Cocos2d-js开发一款《保卫萝卜》手游,cocos2d创始人 王哲 亲自为本书作序!是一部非常优秀的开发书籍!
一线资深游戏开发工程师根据Cocos2D-X 最新版本撰写,Cocos2D-X创始人王哲、CSDN创始人蒋涛联袂推荐 完全通过真实游戏案例驱动,不仅将Cocos2D-X的各种功能、原理、技巧融入其中,而且还详细讲解了空战类、塔防类、...
精通Cocos2d-x游戏开发(进阶卷)源代码 精通Cocos2d-x游戏开发(进阶卷)源代码 精通Cocos2d-x游戏开发(进阶卷)源代码
资源名称:Cocos2d-X案例开发大全内容简介:《Cocos2d-X案例开发大全》包括大量基于Cocos2d-X开发的游戏案例,详细讲解了基于Cocos2d-X游戏引擎在Android及iOS平台下进行游戏开发的思路,能够快速帮助读者提升利用...
在使用cocos2d-x开发游戏的过程中,为了实现逻辑和显示相分离。 在下通宵了一个晚上,写出了该事件类。 谨记,该事件只能用于cocos2d-x中。 事件发送者需要继承EventDispatcher类 事件接收者需要继承EventHandle类...
如果你想用cocos2d开发android游戏,但是又不方便找包,这里就可以为你提供cocos2d开发的所有相关包,解压后得到libs文件夹即可。
ios上基于cocos2d开发的连连看源码。内含cocos2d类库,可以直接编译运行。 居然这么多人下,不是咱写的,赚点分就行。免费啦。
Cocos2D-x游戏开发之音乐播放
cocos2d的学习资料,一本比较经典的cocos2d开发书,适合cocos2d/cocos2d-x的入门