我希望使用当前位置获取最小和最大纬度和经度。假设我提供了一个20公里的区域,使用该纬度和经度,我想要最大纬度和经度以及最小纬度和经度,并且还想要在此之间的所有纬度和经度,那么我该如何获得呢?如何在其中使用半径?请帮助我。谢谢!
我希望使用当前位置获取最小和最大纬度和经度。假设我提供了一个20公里的区域,使用该纬度和经度,我想要最大纬度和经度以及最小纬度和经度,并且还想要在此之间的所有纬度和经度,那么我该如何获得呢?如何在其中使用半径?请帮助我。谢谢!
您可以手动计算它...我不知道是否存在其他方法 1°纬度=69.047英里=60海里 =111.12公里
因此,对于20公里,大约为0.18纬度 对于经度,转换与纬度相同,只是该值乘以纬度的余弦值。
要在地图上设置相同的显示范围
newRegion.center=newLocation.coordinate;
// newRegion.span.latitudeDelta = (20*2)/111.12; // For kilometers
newRegion.span.latitudeDelta = (20*2)/60.0; // For Miles
newRegion.span.longitudeDelta = ((20*2)/60.0) *(cos(newRegion.span.latitudeDelta)); // For Miles
mapView.region = newRegion;
它会在地图上设置20公里的范围,以便您可以通过
来查找它
您可以通过
来找到它minLattitude = currentLattitude - (RadiusInKm/111.12);
maxLattitude = currentLattitude + (RadiusInKm/111.12);
如果经度相同,但需要将结果乘以纬度的余弦值...
1) 将角度转换为弧度的宏:
#define DEGREES_TO_RADIANS(degrees) (degrees / 180.0 * M_PI)
2) 将宏转换为公里半径:
#define radiusInKM 5.00
3)设置纬度和经度的最小和最大值
CLLocation *location;//your current location
1° latitude = 69.047 statute miles = 60 nautical miles = 111.12 kilometers
double minLat = location.coordinate.latitude - (radiusInKM/111.12);
double maxLat = location.coordinate.latitude + (radiusInKM/111.12);
double minLon = location.coordinate.longitude - (radiusInKM) / fabs(cos(DEGREES_TO_RADIANS(location.coordinate.longitude))*111.12);
double maxLon = location.coordinate.longitude + (radiusInKM) / fabs(cos(DEGREES_TO_RADIANS(location.coordinate.longitude))*111.12);
宏定义将度数转换为弧度
宏定义半径为公里
设置最小和最大纬度、经度值
CLLocation *location;//您当前的位置
1° 纬度 = 69.047 英里 = 60 海里 = 111.12 公里
double minLat = location.coordinate.latitude - (radiusInKM/111.12);
double maxLat = location.coordinate.latitude + (radiusInKM/111.12);
double minLon = location.coordinate.longitude - (radiusInKM) / fabs(cos(DEGREES_TO_RADIANS(location.coordinate.longitude))*111.12);
double maxLon = location.coordinate.longitude + (radiusInKM) / fabs(cos(DEGREES_TO_RADIANS(location.coordinate.longitude))*111.12);