手机定位 coco2d开发(不同版本不同方法)
来源:互联网 发布:mac的qq可以远程吗 编辑:程序博客网 时间:2024/05/22 08:15
手机定位 需要实现代理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
- 手机定位 coco2d开发(不同版本不同方法)
- 手机定位 coco2d开发
- GPS定位与手机定位之不同
- [Android开发] 整合不同版本的android project的方法
- [周五]valus_n来适配不同版本手机显示不同thme问题
- android一个应用如何在一个手机上装多个不同版本的方法
- iOS 根据不同的系统版本加载不同图片方法
- GCC不同版本的编译方法
- iOS不同版本获取UDID的方法
- Mac 系统不同jdk版本切换方法
- Mac系统不同jdk版本切换方法
- linux不同版本间驱动加载方法
- 不同版本的Jdk 配置方法
- VC++获取不同Windows版本的方法
- Caffe 不同版本之间layer移植方法
- VASP不同版本的安装方法
- 装两个不同版本MySQL的方法
- hibernate不同版本中sessionFactory获取方法
- Socket Linux和Windows下的区别
- sd卡---spi协议
- Ant 常见问题
- 全面分析 Spring 的编程式事务管理及声明式事务管理 (超详细)
- 企业管理软件永远只是锦上添花?
- 手机定位 coco2d开发(不同版本不同方法)
- Android获取SD卡容量的两种方法
- 成为软件高手的7个致命忌讳
- RVM实用指南
- 一级市场
- 文本框走动跑马灯
- Winfrom中窗体的传值
- bash读取启动文件问题-bash_profile
- 转一篇比较详细介绍FatFs文件系统移植的文章