How can i get minimum and maximum latitude and longitude using current location and radius?

后端 未结 3 1231
死守一世寂寞
死守一世寂寞 2020-12-30 17:18

I want Minimum and Maximum Latitude and Longitude Using Current Location.Suppose i have give the area of 20km so using that latitude and Longitude i want Maximum latitude an

3条回答
  •  情歌与酒
    2020-12-30 17:52

    1) Macros to convert Degrees to Radians:

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

    2) Macros to raduis in KM:

    #define radiusInKM 5.00
    

    3) Set the minimum and maximum Latitude, Longitude values

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

提交回复
热议问题