2013-04-08 58 views
1

我正在從mkmapview獲取路線,我從這個answer得到了代碼。mkmapview中獲取方向的問題

在功能

- (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]]; 
} 

我得到了一些小問題,搜索解決方案,但我不能。

的問題是

1.Parse問題

Expected a type 

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

2.自動引用計數問題

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

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

如何解決這兩個問題?

+0

有什麼建議? – NAZIK 2013-04-08 10:33:34

回答

2

除了機器人貓的回答,儘量做到以下幾點:

  1. 轉到:This code.google Project(如,我是從那裏)
  2. 打開封閉的文件夾
  3. 查找RegexKitLite在它的文件夾。
  4. 將它添加到您的項目(啓用copy file to destination groupAdd to target選項)
  5. 添加#import RegexKitLite.h.m文件。

這個問題很可能會解決。

+0

雖然做這個錯誤說「ld:symbol(s)not found for architecture i386」found,如何解決這個問題? – NAZIK 2013-04-08 12:46:54

+0

您必須在您的項目設置中添加架構'i386'。只是谷歌它。你會得到的。 – viral 2013-04-08 12:49:03

+1

加入庫libicucore.A.dylib和libicucore.dylib解決了這個問題。 – NAZIK 2013-04-10 06:20:45

3

1:聽起來像是一個進口問題。請向我們展示您的頭文件和實現文件中的導入。

2:這不是ARC問題。您正在調用NSString上不存在的方法。同樣,我會建議這是一個導入問題,您忘記導入將方法添加到NSString的類別。將其導入到您的實施文件中。如果你沒有這個類別的代碼,那麼你需要在網上找到它。

+0

thanx對於建議 – NAZIK 2013-04-10 06:21:08

4

試試這個

  1. 刪除文件RegexKitLite.h和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]]; 
    }