Hoe maak je links-top en rechts-bottom lengte- en breedtegraad van kaart in MapKit krijgen

stemmen
9

Hoe maak je links-top en rechts-bottom lengte- en breedtegraad van kaart in MapKit krijgen? Ik gebruik deze code, maar het werkt niet goed. Hoe moet ik dat op?

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];
De vraag is gesteld op 02/12/2009 om 10:05
bron van user
In andere talen...                            


2 antwoorden

stemmen
25

Er is een veel eenvoudiger benadering om het verkrijgen van die coördinaten ... Gebruik het aantal punten dat je bekijken en om te zetten:

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];
antwoordde op 02/12/2009 om 10:13
bron van user

stemmen
2

Ik gebruik Swift2.0, ik heb gemaakt extensionvoorMKMapView

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)
    }
}
antwoordde op 24/01/2016 om 15:46
bron van user

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