计算iOS中地图上位置的边界框

时间:2015-06-24 10:07:04

标签: ios iphone mkmapview

如何从位置计算西南和东北坐标。我没有MKMapView。我只需要根据CLLocationCoordinate2D进行计算。

1 个答案:

答案 0 :(得分:0)

找到它:

#define DEGREE(RADIANS) (180/M_PI) * RADIANS

#define RADIANS(DEGREE) (M_PI/180) * DEGREE

    double lat = [[_locManager location] coordinate].latitude;

    double lon = [[_locManager location] coordinate].longitude;

    double R = 6371; // earth radius in km

    double radius = 0.5; // bounding box spacing from current location in kilo meters

    double y2 = lon + DEGREE(radius/R/cos(RADIANS(lat)));

    double y1 = lon - DEGREE(radius/R/cos(RADIANS(lat)));

    double x2 = lat + DEGREE(radius/R);

    double x1 = lat - DEGREE(radius/R);

x1,y1是西南纬经和x2,y2是东北纬经经度