博客> map范围变化Delegate 代码部分
map范围变化Delegate 代码部分
2019-10-13 20:18 评论:0 阅读:513 魔灵

当手势开始(拖拽,放大,缩小,双击)
mapView:regionWillChangeAnimated:
当手势结束(拖拽,放大,缩小,双击)
mapView:regionDidChangeAnimated:
判断坐标是否在MapView显示范围内:
CLLocationDegrees leftDegrees = mapView.region.center.longitude –(mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees rightDegrees = mapView.region.center.longitude +(mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees bottomDegrees = mapView.region.center.latitude –(mapView.region.span.latitudeDelta / 2.0);
CLLocationDegrees topDegrees = self.region.center.latitude +(mapView.region.span.latitudeDelta / 2.0);

if (leftDegrees > rightDegrees)
{ // Int'l Date Line in View
leftDegrees = -180.0 - leftDegrees;
if (coords.longitude > 0) // coords to West of Date Line
coords.longitude = -180.0 - coords.longitude;
}

if (leftDegrees <= coords.longitude
&& coords.longitude <= rightDegrees
&& bottomDegrees <= coords.latitude
&& coords.latitude <= topDegrees)
{
// 坐标在范围内
}

收藏
0
sina weixin mail 回到顶部