J'essaie le polygone GMSPolygon * = [GMSPolygon polygonWithPath: rect]; méthode pour dessiner un polygone des coordonnées tapées par l'user. Voici comment je stocke les coordonnées sur lesquelles j'ai cliqué:
// array made of clicked coordinates NSMutableArray *latitudeTappedCoordinates = [NSMutableArray array]; NSMutableArray *longitudeTappedCoordinates = [NSMutableArray array]; NSUInteger numberOfLongitudeCoordinates = [longitudeTappedCoordinates count]; NSUInteger numberOfLatitudeCoordinates = [latitudeTappedCoordinates count]; for (int i = 2; i < numberOfLatitudeCoordinates; i++) { [latitudeTappedCoordinates addObject:[NSNumber numberWithInt:coordinate.latitude]]; } for (int i = 2; i < numberOfLongitudeCoordinates; i++) { [longitudeTappedCoordinates addObject:[NSNumber numberWithInt:coordinate.longitude]]; }
Après cela, j'ai ce qui suit:
// polygon GMSMutablePath *rect = [GMSMutablePath path]; [rect addCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)]; GMSPolygon *polygon = [GMSPolygon polygonWithPath:rect];
Comme vous pouvez le voir, la ligne
[rect addCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)];
ne prend qu'un seul atsortingbut. Je veux qu'il prenne toutes les valeurs dans les arrays init ci-dessus, ainsi il peut dessiner le polygone. Comment puis je faire ça?
Les valeurs float du premier magasin ne sont pas des valeurs int dans le tableau. puis
Ajouter dans l'interface
NSMutableArray *latitudeTappedCoordinates; NSMutableArray *longitudeTappedCoordinates;
Vous pouvez faire comme ceci:
// Create a rectangular path GMSMutablePath *rect = [GMSMutablePath path]; CLLocationCoordinate2D event; for (int i = 0; i <= [longitudeTappedCoordinates count]-1; i++) { event.latitude = [[latitudeTappedCoordinates objectAtIndex:i] floatValue]; event.longitude = [[longitudeTappedCoordinates objectAtIndex:i] floatValue]; [rect addCoordinate:event]; } GMSPolygon *polygon = [GMSPolygon polygonWithPath:rect]; polygon.fillColor = [UIColor colorWithRed:0.25 green:0 blue:0 alpha:0.05]; polygon.strokeColor = [UIColor blackColor]; polygon.strokeWidth = 2; polygon.map = mapView;