Reputation: 8444
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?
Upvotes: 1
Views: 1908
Reputation: 524
Try this one
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]];
}
Upvotes: 4
Reputation: 4208
In addition to Robotic Cat's answer, try to do following:
RegexKitLite
Folder in it.copy file to destination group
AND
Add to target
options enabled)#import RegexKitLite.h
to your .m
file.Most probably the problem will be solved.
Upvotes: 2
Reputation: 5891
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.
Upvotes: 3