我一直在使用此链接从此链接的内容中获取折线点
我有这个表达式来获得折线点
NSString* apiUrlStr = [NSString stringWithFormat:@"http://maps.google.com/maps??output=dragdir&saddr=%@&daddr=%@", saddr, daddr];
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]];
但是此代码会在回复
中将encodedPoints
返回给nil
这是来自XCode上面链接的回复:
链接到代码:RESPONSE Content
如何使用正则表达式获取编码点? 我的代码有什么问题?它在2天之前工作正常。我不知道是什么问题。
答案 0 :(得分:1)
You really should to use a WebService. Google Maps provides API.
Your issue is that you're downloading the web page. You said it was working two days ago? Well, they may have change their page since then.
For example, there is nowhere the string "points:
" in the document. That why your regex fails. If tomorrow they change the source code of their page (as it may have happened since two days ago), you're good to redo it, whereas an API should not change (or at least keeps it working for a few moments, years, etc. the deprecated version).