如何使用当前位置和半径获取最小和最大纬度和经度?

3

我希望使用当前位置获取最小和最大纬度和经度。假设我提供了一个20公里的区域,使用该纬度和经度,我想要最大纬度和经度以及最小纬度和经度,并且还想要在此之间的所有纬度和经度,那么我该如何获得呢?如何在其中使用半径?请帮助我。谢谢!

3个回答

6

您可以手动计算它...我不知道是否存在其他方法 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);

如果经度相同,但需要将结果乘以纬度的余弦值...


我现在有当前位置和半径,我想找到最小纬度/经度和最大纬度/经度(区域),我该如何找到这些... - Ankit Vyas
嗨,Ankit, 你可以通过以下方式找到它: minLattitude = currentLattitude - (RadiusInKm/111.12); maxLattitude = currentLattitude + (RadiusInKm/111.12);对于经度,同样的方法,但要将结果乘以纬度的余弦值...我正在答案中更新相同的内容... - Mihir Mehta
双精度型变量minLattitude、maxLattitude、minLongitude和maxLongitude;minLattitude = self.currentLocation.latitude - ((LOCATE_PIN_MILE*1.609344)/111.12); minLongitude = self.currentLocation.longitude * cos(minLattitude);maxLattitude = self.currentLocation.latitude + ((LOCATE_PIN_MILE*1.609344)/111.12); maxLongitude = self.currentLocation.longitude * cos(maxLattitude);这样可以吗? 其中LOCATE_PIN_MILE是英里为单位。 我得不到正确的结果。 请给我建议。 - Ankit Vyas
使用 LOCATE_PIN_MILE/60 直接计算或者 LOCATE_PIN_MILE*2/60 计算之一应该可以工作。 - Mihir Mehta
半径为1公里,位置为41.650476 -0.872905,结果为:Mlat41.659475 mLon0.596298 mLat41.641477 MLon0.607675。因此,它不能作为一般解决方案。 - doxsi

0

1) 将角度转换为弧度的宏:

#define DEGREES_TO_RADIANS(degrees) (degrees / 180.0 * M_PI)

2) 将宏转换为公里半径:

#define radiusInKM 5.00

3)设置纬度和经度的最小和最大值

CLLocation *location;//your current locationlatitude = 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);

-1
  1. 宏定义将度数转换为弧度

    #define DEGREES_TO_RADIANS(degrees) (degrees / 180.0 * M_PI)

  2. 宏定义半径为公里

    #define radiusInKM 5.00

  3. 设置最小和最大纬度、经度值

    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);


不确定这与已接受的答案有何实质性区别,但至少删除其中一个答案。 - Foon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接