[定位]获取经纬度,街道信息

[objc]
CLLocationManager *locManager=[[CLLocationManager alloc]init]; //创建位置管理器
locManager.desiredAccuracy=kCLLocationAccuracyBest; //指定需要的精度级别
locManager.distanceFilter=100; //设置距离筛选器
[locManager startUpdatingLocation]; //启动更新位置管理

CLLocationDegrees latitude = locManager.location.coordinate.latitude; //float也行,获取当前位置的纬度
CLLocationDegrees longitude = locManager.location.coordinate.longitude; //float也行,获取当前位置的经度
NSLog(@"latitude %f",latitude);
NSLog(@"longitude %f",longitude);

if (longitude == latitude && latitude == 0) {
NSLog(@"定位失败");

}else{

CLGeocodeCompletionHandler handler = ^(NSArray *place, NSError *error) {

for (CLPlacemark *placemark in place) {

NSString *country=[placemark.addressDictionary objectForKey:@"Country"];

NSLog(@"Country %@",country);//国家

NSString *state=[placemark.addressDictionary objectForKey:@"State"];

NSLog(@"State %@",state);//省份

NSString *city=[placemark.addressDictionary objectForKey:@"City"];

NSLog(@"city %@",city);//城市

NSString *street=[placemark.addressDictionary objectForKey:@"Street"];

NSLog(@"Street %@",street);//街道

NSString *addr=[NSString stringWithFormat:@"%@ %@ %@ %@",country,state,city,street];

NSLog(@"addr %@",addr);

break;

}

};

//反向地理编码
CLGeocoder *Geocoder=[[CLGeocoder alloc]init];
CLLocation *loc = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
[Geocoder reverseGeocodeLocation:loc completionHandler:handler];

}
[/objc]

89 thoughts on “[定位]获取经纬度,街道信息

  1. Mlhwdu

    Boostez vos performances avec notre espace dedie aux sportifs. Complements alimentaires, proteines et soins musculaires sont disponibles. Preparez vos efforts et votre recuperation avec des produits de pointe. Commandez votre nutrition sportive facilement en ligne.zebeta

  2. Cyodmc

    FanDuel Casino is America’s #1 online casino, delivering unhesitating thrills with ignition casino bonus 2026 , aristocratic slots like Huff N’ Puff, and last dealer act right at your fingertips. Hip players make 500 Bonus Spins together with $40 in Casino Compensation upstanding for the purpose depositing $10—bonus up to $1,000 back on first-day reticle losses. Calling all Thrillionaires: be adjacent to at present, butter up your approach, and construct every moment into epic wins!

发表评论

电子邮件地址不会被公开。