iOS-百度地圖螢幕所顯示範圍內的經緯度

weixin_34378969發表於2018-08-29

今天用到百度地圖獲取螢幕範圍內的經緯度,在此記錄一下。

    // 當前螢幕中心點的經緯度
    double centerLongitude = self.mapView.region.center.longitude;
    double centerLatitude = self.mapView.region.center.latitude;

    //當前螢幕顯示範圍的經緯度
    CLLocationDegrees pointssLongitudeDelta = self.mapView.region.span.longitudeDelta;
    CLLocationDegrees pointssLatitudeDelta = self.mapView.region.span.latitudeDelta;

    //左上角
    double leftUpLong = centerLongitude - pointssLongitudeDelta/2.0;
    double leftUpLati = centerLatitude - pointssLatitudeDelta/2.0;

    //右上角
    double rightUpLong = centerLongitude + pointssLongitudeDelta/2.0;
    double rightUpLati = centerLatitude - pointssLatitudeDelta/2.0;

    //左下角
    double leftDownLong = centerLongitude - pointssLongitudeDelta/2.0;
    double leftDownlati = centerLatitude + pointssLatitudeDelta/2.0;

    //右下角
    double rightDownLong = centerLongitude + pointssLongitudeDelta/2.0;
    double rightDownLati = centerLatitude + pointssLatitudeDelta/2.0;

    NSLog(@"\n 左上   %f,%f---------\n 右上   %f,%f-------\n 左下  %f,%f----- \n 右下  %f,%f",leftUpLong,leftUpLati,rightUpLong,rightUpLati,leftDownLong,leftDownlati,rightDownLong,rightDownLati);

相關文章