#pragma mark 地图相关
-(void)locan
{
self.locationManager = [[CLLocationManager alloc]init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.distanceFilter = 10;
if (IsIOS8) {
[_locationManager requestAlwaysAuthorization];
}
[_locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *currLocation = [locations lastObject];
lat =currLocation.coordinate.latitude;
lon =currLocation.coordinate.longitude;
[_locationManager stopUpdatingLocation];
//第一个坐标
CLLocation *current=[[CLLocation alloc] initWithLatitude:lat longitude:lon];
//第二个坐标
CLLocation *before=[[CLLocation alloc] initWithLatitude:oneMode.y.doubleValue longitude:oneMode.x.doubleValue];
// 计算距离
CLLocationDistance meters=[current distanceFromLocation:before];
jlLabel.text =[NSString stringWithFormat:@"%.2fkm",meters/1000];
CLLocation *c = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
//创建位置
CLGeocoder *revGeo = [[CLGeocoder alloc] init];
[revGeo reverseGeocodeLocation:c
//反向地理编码
completionHandler:^(NSArray *placemarks, NSError *error) {
if (!error && [placemarks count] > 0)
{
NSDictionary *dict =
[[placemarks objectAtIndex:0] addressDictionary];
NSLog(@"street address: %@",
//记录地址
[dict objectForKey:@"Name"]);
NSString *str =[dict objectForKey:@"Name"];
str =[str stringByReplacingOccurrencesOfString:@"中国" withString:@""];
myAdder=str;
}
else
{
NSLog(@"ERROR: %@", error); }
}];
}