就是令MKMapView懂得自動移去兩個地圖子針之間的位置,
令用戶可以知道目的地同自己差多遠,
最後看了一下MKMapView的Document就找到了,
倒不算太難,
留下來作筆記XD
// 獲取用戶的位置範圍
MKMapPoint userMapPoint = MKMapPointForCoordinate(userLocation.location.coordinate);
MKMapRect userRect = MKMapRectMake(userMapPoint.x, userMapPoint.y, 50, 50);
// 獲取目的地的位置範圍
MKMapPoint targetMapPoint = MKMapPointForCoordinate(_coordinate);
MKMapRect targetRect = MKMapRectMake(targetMapPoint.x, targetMapPoint.y, 50, 50);
// 把範圍Union
MKMapRect unionRect = MKMapRectUnion(userRect, targetRect);
// 叫MKMapView移去指定範圍
[_mapView setVisibleMapRect:unionRect animated:TRUE];
MKMapPoint userMapPoint = MKMapPointForCoordinate(userLocation.location.coordinate);
MKMapRect userRect = MKMapRectMake(userMapPoint.x, userMapPoint.y, 50, 50);
// 獲取目的地的位置範圍
MKMapPoint targetMapPoint = MKMapPointForCoordinate(_coordinate);
MKMapRect targetRect = MKMapRectMake(targetMapPoint.x, targetMapPoint.y, 50, 50);
// 把範圍Union
MKMapRect unionRect = MKMapRectUnion(userRect, targetRect);
// 叫MKMapView移去指定範圍
[_mapView setVisibleMapRect:unionRect animated:TRUE];
沒有留言:
張貼留言