내 생각 엔 '근처'는 화면 상단의 모서리입니다 '까지'화면 하단의보기의 모서리를 위해, 그리고 있다는 점이다. 왜냐하면보기를 기울이면 가장 아래쪽 모서리가 카메라에 가장 가깝고 위쪽 모서리가 카메라에서 가장 멀리 떨어져 있기 때문입니다.
CLRegion
으로 바꾸는 한 가지 방법은 카메라의 타겟을 가운데로 사용한 다음 최대 거리에서 네 모서리까지 반경을 계산하는 것입니다. 이 지역에 가장 적합한 피팅 서클이 아닐 수도 있지만 어쨌든 원이보기의 사변형에 맞지 않을 수 있으므로 충분히 가까울 수 있습니다.
double getDistanceMetresBetweenLocationCoordinates(
CLLocationCoordinate2D coord1,
CLLocationCoordinate2D coord2)
{
CLLocation* location1 =
[[CLLocation alloc]
initWithLatitude: coord1.latitude
longitude: coord1.longitude];
CLLocation* location2 =
[[CLLocation alloc]
initWithLatitude: coord2.latitude
longitude: coord2.longitude];
return [location1 distanceFromLocation: location2];
}
그 다음 CLRegion
이렇게 계산 될 수있다 :
GMSMapView* mapView = ...;
...
CLLocationCoordinate2D centre = mapView.camera.target;
GMSVisibleRegion* visibleRegion = mapView.projection.visibleRegion;
double nearLeftDistanceMetres =
getDistanceMetresBetweenLocationCoordinates(centre, visibleRegion.nearLeft);
double nearRightDistanceMetres =
getDistanceMetresBetweenLocationCoordinates(centre, visibleRegion.nearRight);
double farLeftDistanceMetres =
getDistanceMetresBetweenLocationCoordinates(centre, visibleRegion.farLeft);
double farRightDistanceMetres =
getDistanceMetresBetweenLocationCoordinates(centre, visibleRegion.farRight);
double radiusMetres =
MAX(nearLeftDistanceMetres,
MAX(nearRightDistanceMetres,
MAX(farLeftDistanceMetres, farRightDistanceMetres)));
CLRegion region = [[CLRegion alloc]
initCircularRegionWithCenter: centre radius: radius identifier: @"id"];
UPDATE :
여기
두
CLLocationCoordinate
값 사이에서 m의 거리를 계산하는 도우미 함수의
MKCoordinateRegion
에 대한 업데이트와 관련하여 예제 코드가 작동하지 않을 수 있습니다. rk. 지도가 90도 회전 된 경우
farLeft
과
nearLeft
은 동일한 위도를 가지며
farRight
과
farLeft
은 동일한 경도를 갖기 때문에 위도와 경도의 델타는 0이됩니다.
당신은 farLeft
, farRight
, nearLeft
, nearRight
의 네 돌이 필요 각각의 위도와 경도의 최소 및 최대를 계산 한 다음 그에서 델타를 계산합니다.
iOS 용 Google지도 SDK에는 도우미 클래스가 포함되어 있는데이 도우미 클래스 중 일부는 이미 GMSCoordinateBounds
입니다. GMSVisibleRegion
로 초기화 할 수 있습니다 다음 GMSCoordinateBounds
다음 경계를 정의 northEast
및 southWest
특성을 가지고
GMSMapView* mapView = ...;
....
GMSVisibleRegion visibleRegion = mapView.projection.visibleRegion;
GMSCoordinateBounds bounds =
[[GMSCoordinateBounds alloc] initWithRegion: visibleRegion];
.당신은 델타를 계산할 수 있도록 다음과 같이
CLLocationDegrees latitudeDelta =
bounds.northEast.latitude - bounds.southWest.latitude;
CLLocationDegrees longitudeDelta =
bounds.northEast.longitude - bounds.southWest.longitude;
또한 경계에서 중심을 계산하고 할 수 있으므로 MKCoordinateRegion
: 순수 주의자
당신이 원하는 경우에 대한
CLLocationCoordinate2D centre = CLLocationCoordinate2DMake(
(bounds.southWest.latitude + bounds.northEast.latitude)/2,
(bounds.southWest.longitude + bounds.northEast.longitude)/2);
MKCoordinateSpan span = MKCoordinateSpanMake(latitudeDelta, longitudeDelta);
return MKCoordinateRegionMake(centre, span);
에 MKCoordinateRegion를 사용하여
region
을 얻기에 빠른 확장이 그래이 의미가 있습니다! 귀하의 답변을 평가하기 위해 샘플 코드가 제게 있습니다. 그리고 곧 당신을보고 할 것입니다. 앞으로 더 나은 문서가되기를 바랍니다. –안녕하세요 @ xen100, 나는'MKCoordinateRegion'에 대한 질문의 후반부에 대한 업데이트를 추가했습니다. –
고마워요! 너는 나의 하루를 구했다! :) –