美文网首页
iOS-百度地图获取屏幕显示范围内的经纬度

iOS-百度地图获取屏幕显示范围内的经纬度

作者: tongyuling | 来源:发表于2021-05-25 11:12 被阅读0次
//地图区域改变完成后会调用此接口
- (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    // 当前屏幕中心点的经纬度
    double centerLongitude = self.mapView.region.center.longitude;
    double centerLatitude = self.mapView.region.center.latitude;
    NSLog(@"==中心点经纬度 %f,%f",centerLatitude, centerLongitude);
    
    //当前屏幕显示范围的经纬度
    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);
}

相关文章

网友评论

      本文标题:iOS-百度地图获取屏幕显示范围内的经纬度

      本文链接:https://www.haomeiwen.com/subject/htvqsltx.html