daniegarcia254
daniegarcia254

Reputation: 1197

Google Maps API Directions Service return directions in xml format

I've succesfully done the process of getting the directions:

function getRoute(){
    var formato = $('#formato-bizis-select').val();
    var start = $('#input-origen').val();

    $.post("index.php/calcular-ruta", $('#bizis-form').serialize(), function(data){
        var end = data.lat + "," + data.long;
        var request = {
            origin: start,
            destination: end,
            unitSystem: google.maps.UnitSystem.METRIC,
            travelMode: google.maps.TravelMode.DRIVING
        }
        directionsService.route(request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                directionsDisplay.setDirections(response);
            }
        });
    });
}

And I know, from the documentation, that you can access data in XML or JSON format from this different URLs:

But, the in the directionService.route() method I don't know how to include the URL in the request for indicate the formatI want.

Upvotes: 1

Views: 3188

Answers (1)

Michael Geary
Michael Geary

Reputation: 28860

You're confusing two different APIs:

  • The Directions Service is part of the JavaScript Maps API and is what you use in JavaScript code.
  • The Directions API is an HTTP API for use from server-side code.

The Directions API does have options to return either XML or JSON data to your server-side code.

But since you are writing JavaScript here, you aren't using the Directions API, you're using the Directions Service. This doesn't provide JSON or XML or anything like that, it gives you a JavaScript object that you can use directly in your JavaScript code.

In your code, response is a JavaScript object. You can use the Developer Tools in your browser to look at it directly and see its properties, and you can write JavaScript code to access it directly without having to parse JSON or XML.

Upvotes: 2

Related Questions