定位所在城市
来源:互联网 发布:一个php页面的完整代码 编辑:程序博客网 时间:2024/06/04 18:28
这个方法里- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
--------------------------------------------
//自动定位获取是哪个城市
[locationManager stopUpdatingLocation];
locat=[newLocation coordinate];
CLGeocoder *geocoder=[[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if (placemarks.count>0) {
CLPlacemark *placenark=[placemarks objectAtIndex:0];
NSLog(@"%@============%@",[placenark locality],[placenark subLocality]);
[self showWithlocation:locat];
}
else{
NSLog(@"-------定位失败-----");
}
}];
调用的自定义的一个方法------------------------------------------
-(void)showWithlocation:(CLLocationCoordinate2D)location
{
CLGeocoder*Geocoder=[[CLGeocoder alloc]init];
CLLocation *loc = [[CLLocation alloc] initWithLatitude:location.latitude longitude:location.longitude];
CLGeocodeCompletionHandler handler = ^(NSArray *place, NSError *error) {
for (CLPlacemark *placemark in place) {
NSString *cityStr=[placemark.addressDictionary objectForKey:@"City"];
//访问完数据后将地址存入本地
NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
[userDefaults setObject:cityStr forKey:@"cityName"];
[userDefaults synchronize];
[cityButton setTitle:cityStr forState:UIControlStateNormal];
NSLog(@"%@",cityStr);
break;
}
};
[Geocoder reverseGeocodeLocation:loc completionHandler:handler];
}
--------------------------------------------
//自动定位获取是哪个城市
[locationManager stopUpdatingLocation];
locat=[newLocation coordinate];
CLGeocoder *geocoder=[[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if (placemarks.count>0) {
CLPlacemark *placenark=[placemarks objectAtIndex:0];
NSLog(@"%@============%@",[placenark locality],[placenark subLocality]);
[self showWithlocation:locat];
}
else{
NSLog(@"-------定位失败-----");
}
}];
调用的自定义的一个方法------------------------------------------
-(void)showWithlocation:(CLLocationCoordinate2D)location
{
CLGeocoder*Geocoder=[[CLGeocoder alloc]init];
CLLocation *loc = [[CLLocation alloc] initWithLatitude:location.latitude longitude:location.longitude];
CLGeocodeCompletionHandler handler = ^(NSArray *place, NSError *error) {
for (CLPlacemark *placemark in place) {
NSString *cityStr=[placemark.addressDictionary objectForKey:@"City"];
//访问完数据后将地址存入本地
NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];
[userDefaults setObject:cityStr forKey:@"cityName"];
[userDefaults synchronize];
[cityButton setTitle:cityStr forState:UIControlStateNormal];
NSLog(@"%@",cityStr);
break;
}
};
[Geocoder reverseGeocodeLocation:loc completionHandler:handler];
}
- 定位所在城市
- IOS中定位当前所在城市
- android 根据经纬度定位所在城市
- android 根据经纬度定位所在城市
- 根据IP定位用户所在城市信息
- 根据IP定位用户所在城市信息
- 根据IP定位用户所在城市信息
- 根据IP定位用户所在城市信息
- 根据IP定位用户所在城市信息 (js)
- 根据IP定位用户所在城市信息
- 百度地图定位之获取所在城市
- php 获取公网IP地址、定位所在城市
- 根据IP定位所在城市(HTML,js,新浪IP地址库)
- 关于利用高德地图API定位所在城市的一切知识点整理
- Android GSP定位获取经纬度并显示所在城市的名字(不用引入各种SDK)
- 取IP地址所在城市
- 判断ip 所在城市
- 根据IP得到所在城市
- copy,assign,strong,retain,weak,readonly,nonatomic的区别
- 设计模式之 Designing for Change 变更设计
- 获取应用程序根目录
- 05.数据库设计原则的一些细节
- QT5.0.1在Windows下 出现QApplication: No such file or directory 问题的解决办法
- 定位所在城市
- C++中vector容器类型的使用方法
- Valuestack与getModel
- JUnit4教程
- 前缀数组Trie刘汝佳模板
- Android 问题异常 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
- DS_Store is missing from working copy
- nginx 配置二级域名跳转以及www 跳转(去除www 跳转),nginx 端口跳转,nginx 保留IP信息
- 跟踪Android callback 调用堆栈