Question

I'm trying to fetch the XML result from an exmaple query like this: http://maps.googleapis.com/maps/api/directions/xml?origin=Toronto,ON&destination=Manhattan,NY&dirflg=r&sensor=false

in my program. Is there a way to fetch the XML results in Objective-C code? I don't want my application to open Maps application. I want to be able to receive the XML. I do have a MapKit in my application.

Was it helpful?

Solution

Sure. Just do something like this:

NSXMLParser * xmlParser = 
    [[NSXMLParser alloc] initWithContentsOfURL: [NSURL URLWithString: @"http://maps.googleapis.com/maps/api/directions/xml?origin=Toronto,ON&destination=Manhattan,NY&dirflg=r&sensor=false"];

The Apple documentation for NSXMLParser is here.

This may be a bit too heavy duty for your purposes, so you can also do something like the answers provided for in this duplicate question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top