2009-12-02 5 views
9

MapKit에서지도의 왼쪽 위 및 오른쪽 아래 위도와 경도를 얻는 방법은 무엇입니까? 이 코드를 사용하지만 제대로 작동하지 않습니다. 어떻게 수정해야합니까? 그 좌표를 얻기에 훨씬 쉽게 접근 방식은보기의 포인트를 사용하여 변환 ...이MapKit에서지도의 왼쪽 위 및 오른쪽 아래 위도와 경도를 얻는 방법

MKCoordinateRegion region = [map region]; 

double topL,topG,bottomL,bottomG; 
//if latitude=55 and latitudeDelta=126 topL is 118 and it will be not at top, it will be at buttom of screen 
topL = region.center.latitude + region.span.latitudeDelta/2; 

topG = region.center.longitude - region.span.longitudeDelta/2; 

CLLocationCoordinate2D lt; 
lt.latitude=topL; 
lt.longitude=topG; 
annotation = [Annotation new]; 
annotation.coordinate = lt; 
annotation.title = @"Left"; 
[map addAnnotation:annotation]; 
[annotation release]; 
//if latitude=55 and latitudeDelta=126 bottomL is -7.23 and it will be not at bottom, it will be at above bottom of screen 
bottomL = region.center.latitude - region.span.latitudeDelta/2; 


bottomG = region.center.longitude + region.span.longitudeDelta/2; 

CLLocationCoordinate2D rb; 
rb.latitude=bottomL; 
rb.longitude=bottomG; 
annotation = [Annotation new]; 
annotation.coordinate = rb; 
annotation.title = @"Right"; 
[map addAnnotation:annotation]; 
[annotation release]; 

답변

24

:

CLLocationCoordinate2D topLeft, bottomRight; 
topLeft = [mapView convertPoint:CGPointMake(0, 0) toCoordinateFromView:mapView]; 
CGPoint pointBottomRight = CGPointMake(mapView.frame.size.width, mapView.frame.size.height); 
bottomRight = [mapView convertPoint:pointBottomRight toCoordinateFromView:mapView]; 
+0

감사합니다. 작동합니다. :) –

2

을 내가 Swift2.0를 사용하고, 나는 MKMapView에 대한 extension을 생성

extension MKMapView { 
    func topLeftCoordinate() -> CLLocationCoordinate2D { 
     return convertPoint(CGPoint.zero, toCoordinateFromView: self) 
    } 

    func bottomRightCoordinate() -> CLLocationCoordinate2D { 
     return convertPoint(CGPoint(x: frame.width, y: frame.height), toCoordinateFromView: self) 
    } 
} 
관련 문제