博客> 根据城市名获取经纬度
根据城市名获取经纬度
2019-01-21 21:23 评论:0 阅读:181 912612039

//根据城市名获取经纬度

  • (void)getOreillyAddress:(NSString )cityName { NSString oreillyAddress = cityName; CLGeocoder myGeocoder = [[CLGeocoder alloc] init]; [myGeocoder geocodeAddressString:oreillyAddress completionHandler:^(NSArray placemarks, NSError error) { if ([placemarks count] > 0 && error == nil) { NSLog(@"Found %lu placemark(s).", (unsigned long)[placemarks count]); CLPlacemark firstPlacemark = [placemarks objectAtIndex:0]; NSLog(@"Longitude = %f", firstPlacemark.location.coordinate.longitude); NSLog(@"Latitude = %f", firstPlacemark.location.coordinate.latitude); [_mapView setCenterCoordinate:firstPlacemark.location.coordinate animated:YES] ; } else if ([placemarks count] == 0 && error == nil) { NSLog(@"Found no placemarks."); } else if (error != nil) { NSLog(@"An error occurred = %@", error); } }]; }
收藏
0
sina weixin mail 回到顶部