9
votes

iPhone MKMAPView - Problèmes Mkpolygon

J'essaie de tracer un mkpolygon sur un MkmapView dans iOS 4.0. J'ai un nsarray qui contient des objets personnalisés qui incluent des propriétés pour la latitude / la longitude. J'ai un échantillon de code ci-dessous:

- (void)viewDidLoad {
    [super viewDidLoad];
    dataController = [[DataController alloc] initWithMockData];
    coordinateData = [dataController getCordData];

    CLLocationCoordinate2D *coords = NULL;
    NSUInteger coordsLen = 0;

    /* How do we actually define an array of CLLocationCoordinate2d? */

    MKPolygon *polygon = [MKPolygon polygonWithCoordinates:coords count:coordsLen];
    [mapView addOverlay: polygon];

}

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKPolygonView *polygonView = [[MKPolygonView alloc] initWithPolygon: routePolygon]; 
    NSLog(@"Attempting to add Overlay View");   
    return polygonView;
}


0 commentaires

4 Réponses :


17
votes

La méthode PolygonWithcoordinates veut une gamme C de structs CLLOCOCOCOCORINATION2D. Vous pouvez utiliser masloc code> pour allouer la mémoire pour le tableau (et gratuit code> pour libérer la mémoire). Boucle à travers votre Nsarray et réglez-le chaque élément du tableau de struct.

Par exemple: P>

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKPolygonView *polygonView = [[[MKPolygonView alloc] initWithPolygon:overlay] autorelease]; 
    polygonView.lineWidth = 1.0;
    polygonView.strokeColor = [UIColor redColor];
    polygonView.fillColor = [UIColor greenColor];
    return polygonView;
}


0 commentaires

2
votes

pour iOS 7.0 et plus tard, nous devrions utiliser mkpolygonrenderer au lieu de mkpolygonview , xxx


0 commentaires

0
votes

coordonnéesArray; // Votre matrice contenant les coordonnées xxx

// Votre "coordinatesarray" est un tableau contenant le dictionnaire avec plusieurs valeurs de la latitude et des touches de longitude. // espère que cela vous aide.


0 commentaires

1
votes

code dans Swift 4 em> strud>

pour coordonnées dans JSON: p> xxx pré>

lire les coordonnées: P>

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
    if overlay is MKPolygon {
        let polygonView = MKPolygonRenderer(overlay: overlay)
        polygonView.fillColor = .black
        polygonView.strokeColor = .red
        polygonView.lineWidth = 2.0

        return polygonView

    return MKOverlayRenderer()
}


0 commentaires