I know this is really late, but I'm posting my solution to this in case anybody needs it.
Firstly, i declared the URL (the one that calls google maps api)
#define DST_API @"http://maps.googleapis.com/maps/api/distancematrix/xml?origins=%@&destinations=%@&units=%@&sensor=false"
Next I created a string containing this URL:
NSString *URL = [NSString stringWithFormat:DST_API, source, destination, units];
Where source, destination are strings containing the start point and end point. units can be @"imperial" or @"metric".
Now that i had the URL, i would get back an xml string. To parse this, i used TBXML. There is always a large debate about which XML Parser to use. I used TBXML as it was easy, and is the fastest.
TBXML *directionsParser = [[TBXML alloc] initWithURL:[NSURL URLWithString:URL]];
// Check if the Overall status is OK
TBXMLElement *root = directionsParser.rootXMLElement;
TBXMLElement *element = [TBXML childElementNamed:@"status" parentElement:root];
NSString *value = [TBXML textForElement:element];
if ([value caseInsensitiveCompare:@"OK"] != NSOrderedSame) {
[directionsParser release];
return result;
}
Once checking the root status is OK, then obtain the result for the XPath expression: //row/element/distance/value
element = [TBXML childElementNamed:@"row" parentElement:root];
element = [TBXML childElementNamed:@"element" parentElement:element];
element = [TBXML childElementNamed:@"status" parentElement:element];
value = [TBXML textForElement:element];
// Check if the Element status is OK
if ([value caseInsensitiveCompare:@"OK"] != NSOrderedSame) {
[directionsParser release];
return result;
}
element = element->parentElement;
element = [TBXML childElementNamed:@"distance" parentElement:element];
//Note if you want the result as text, replace 'value' with 'text'
element = [TBXML childElementNamed:@"value" parentElement:element];
NSString *result = [TBXML textForElement:element];
[directionsParser release];
//Do what ever you want with result
If anyone wants to have a URL to include way points, then here it is
#define DIR_API @"http://maps.googleapis.com/maps/api/directions/xml?origin=%@&destination=%@&waypoints=%@&units=%@&sensor=false"
But to use way points, things work a bit differently as Jano pointed out.