Question

I'm working with getting directions in mkmapview, I got code from this answer.

In the function

- (NSArray*)getRoutePointFrom:(Annotation *)origin to:(Annotation *)destination
{
NSString* saddr = [NSString stringWithFormat:@"%f,%f", origin.coordinate.latitude, origin.coordinate.longitude];
NSString* daddr = [NSString stringWithFormat:@"%f,%f", destination.coordinate.latitude, destination.coordinate.longitude];

NSString* apiUrlStr = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@", saddr, daddr];
NSURL* apiUrl = [NSURL URLWithString:apiUrlStr];

NSError *error;
NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl encoding:NSUTF8StringEncoding error:&error];
NSString* encodedPoints = [apiResponse stringByMatching:@"points:\\\"([^\\\"]*)\\\"" capture:1L];

return [self decodePolyLine:[encodedPoints mutableCopy]];
}

I got some small issues, searched for solutions, but I can't.

The issues are

1.Parse Issue

Expected a type 

in

- (NSArray*)getRoutePointFrom:(Annotation *)origin to:(Annotation *)destination

2.Automatic Reference counting issue

 'NSString' for instance message does not declare a method with selector 'stringByMatching:capture:'

in

NSString* encodedPoints = [apiResponse stringByMatching:@"points:\\\"([^\\\"]*)\\\"" capture:1L];

How to solve these two issues?

Was it helpful?

Solution 3

In addition to Robotic Cat's answer, try to do following:

  1. Goto: This code.google Project (As, I got that from there)
  2. Open the enclosing folder
  3. Find RegexKitLite Folder in it.
  4. Add it to your project (with copy file to destination group AND Add to target options enabled)
  5. Add #import RegexKitLite.h to your .m file.

Most probably the problem will be solved.

OTHER TIPS

Try this one

  1. Delete the file RegexKitLite.h and RegexKitLite.m

    -(NSArray*) calculateRoutesFrom:(CLLocationCoordinate2D) f to: (CLLocationCoordinate2D) t {
        NSString* saddr = [NSString stringWithFormat:@"%f,%f", f.latitude, f.longitude];
        NSString* daddr = [NSString stringWithFormat:@"%f,%f", t.latitude, t.longitude];
    
        NSString* apiUrlStr = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@", saddr, daddr];
        NSURL* apiUrl = [NSURL URLWithString:apiUrlStr];
        NSLog(@"api url: %@", apiUrl);
        NSError *error;
        NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl encoding:NSUTF8StringEncoding error:&error];
        NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"points:\\\"([^\\\"]*)\\\"" options:0 error:NULL];
        NSTextCheckingResult *match = [regex firstMatchInString:apiResponse options:0 range:NSMakeRange(0, [apiResponse length])];
        NSString *encodedPoints = [apiResponse substringWithRange:[match rangeAtIndex:1]];
        //NSString* encodedPoints = [apiResponse stringByMatching:@"points:\\\"([^\\\"]*)\\\"" capture:1L];
    
        return [self decodePolyLine:[encodedPoints mutableCopy]];
    }
    

1: Sounds like an import issue. Please show us your imports in your header file and implementation files.

2: This is NOT an ARC issue. You are calling a method that does not exist on NSString. Again, I would suggest that this is an import issue where you have forgotten to import a category that adds methods to NSString. Import it into your implementation file. If you don't have this category code then you will need to find it on the web somewhere.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top