0

I'm trying to highlight an area between two polylines like this:

enter image description here

I have calculated the left and right polylines. To highlight the inside I am using a polygon that has points of the left side plus the right side in reverse (to properly close the polygon). The GMSMutablePath has no function to reverse the array so I did this:

       for (NSUInteger i1 = 0; i1 < [reversedRight count]/2; i1 ++)
    { NSUInteger i2 = [reversedRight count]-i1;
        CLLocationCoordinate2D coord1 = [reversedRight coordinateAtIndex:i1];
        CLLocationCoordinate2D coord2 = [reversedRight coordinateAtIndex:i2];
        [reversedRight replaceCoordinateAtIndex:i1 withCoordinate:coord2];
        [reversedRight replaceCoordinateAtIndex:i2 withCoordinate:coord1];}

Neither is there anyway to combine the GMSMutable Arrays. So I converted them to an encoded String and the concatenated them:

    NSString *pathLeftSt = pathLeft.encodedPath;
    NSString *pathRighSt = reversedRight.encodedPath;

    NSString *spaceASCII = @"32";


    NSString *combinedPaths = [NSString stringWithFormat:@"%@%@%@", pathLeftSt , spaceASCII, pathRighSt];

   fullRectangle = [GMSMutablePath pathFromEncodedPath:combinedPaths];

My path generated looks like this (the left and right paths are correct, but the highlighting is way off: enter image description here

I'm fairly certain my encoding is off. I place "32" between the encoded strings for an ASCII space. The instructions for the encoding algorithm are here: https://developers.google.com/maps/documentation/utilities/polylinealgorithm

Do I need to add something else to properly combine these two strings and place them back into a GMSMutablePath?

johnsonjp34
  • 3,139
  • 5
  • 22
  • 48
  • Eventually if you can't reverse the path, you can make 2 loops when creating left and right polyline, with the second one reversed `for ( var i = path.length ; i > 0 ; i-- )`. Or, on a single loop, you can add left points 1 by 1 (`poinsLeftt[i] = newpointLeft`) and right points with reversed indexes (`pointRight[path.length-i] = newpointRight`). But i don't know the syntaxes of ios dev so it may not be possible ;) – Pierre Granger Jul 27 '17 at 06:50
  • @PierreGranger Thanks again for your help. I initialized a GMSMutablePath with the left side and then looped in reverse to add the right side. It is working great. Thanks! That is a better solution than trying to encode strings to concatenate. – johnsonjp34 Jul 27 '17 at 14:11
  • 1
    Good. In my previous algorithm i had errors (some left were in right and reverse. It depends on the angle before/after the actual point, the calcul wasn't good. I updated me code in https://stackoverflow.com/a/45289641/2846837 : still in js but the algorithm works better than previous (just when angles as too close, it's not "round enough" but still ok. – Pierre Granger Jul 27 '17 at 14:49

0 Answers0