कैसे MapKit में बाएं ऊपर और सही-नीचे अक्षांश और नक्शे के देशांतर प्राप्त करने के लिए

वोट
9

कैसे बाएं ऊपर और सही-नीचे अक्षांश और 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];
02/12/2009 को 10:05
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


2 जवाब

वोट
25

वहाँ उन निर्देशांक ... आपके विचार के अंक का उपयोग करें, और परिवर्तित हो रही करने के लिए एक बहुत आसान तरीका है:

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];
02/12/2009 को 10:13
का स्रोत उपयोगकर्ता

वोट
2

मैं Swift2.0 उपयोग कर रहा हूँ, मैं बनाया extensionके लिएMKMapView

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)
    }
}
24/01/2016 को 15:46
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more