iOS中定位当前位置坐标及转换为火星坐标的方法

2020-01-14 20:05:30丽君

    NSLog(@"error");
}
 
// 6.0 以上调用这个函数
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
     
    NSLog(@"%d", [locations count]);
     
    CLLocation *newLocation = locations[0];
    CLLocationCoordinate2D oldCoordinate = newLocation.coordinate;
    NSLog(@"旧的经度:%f,旧的纬度:%f",oldCoordinate.longitude,oldCoordinate.latitude);
     
//    CLLocation *newLocation = locations[1];
//    CLLocationCoordinate2D newCoordinate = newLocation.coordinate;
//    NSLog(@"经度:%f,纬度:%f",newCoordinate.longitude,newCoordinate.latitude);
     
    // 计算两个坐标距离
    //    float distance = [newLocation distanceFromLocation:oldLocation];
    //    NSLog(@"%f",distance);
     
    [manager stopUpdatingLocation];
     
    //------------------位置反编码---5.0之后使用-----------------
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:newLocation
                   completionHandler:^(NSArray *placemarks, NSError *error){
                        
                       for (CLPlacemark *place in placemarks) {
                           UILabel *label = (UILabel *)[self.window viewWithTag:101];
                           label.text = place.name;
                           NSLog(@"name,%@",place.name);                       // 位置名
//                           NSLog(@"thoroughfare,%@",place.thoroughfare);       // 街道