Search code examples
iphoneiosobjective-cmkmapviewdirections

Issues in getting directions in mkmapview


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?


Solution

  • 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.