简体   繁体   English

Google Maps API路线服务以xml格式返回的路线

[英]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: 我知道,从文档中,您可以从以下不同的URL访问XML或JSON格式的数据:

But, the in the directionService.route() method I don't know how to include the URL in the request for indicate the formatI want. 但是,在directionService.route()方法中,我不知道如何在请求中包括URL以指示我想要的格式。

You're confusing two different APIs: 您会混淆两个不同的API:

  • The Directions Service is part of the JavaScript Maps API and is what you use in JavaScript code. Directions服务是JavaScript Maps API的一部分,也是您在JavaScript代码中使用的服务。
  • The Directions API is an HTTP API for use from server-side code. Directions API是供服务器端代码使用的HTTP API。

The Directions API does have options to return either XML or JSON data to your server-side code. Directions API确实具有将XML或JSON数据返回到服务器端代码的选项。

But since you are writing JavaScript here, you aren't using the Directions API, you're using the Directions Service. 但是,由于您在此处编写JavaScript,因此您没有使用Directions API,而是使用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. 它不提供JSON或XML或类似的东西,它为您提供了一个JavaScript对象,您可以直接在JavaScript代码中使用它。

In your code, response is a JavaScript object. 在您的代码中, response是一个JavaScript对象。 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. 您可以在浏览器中使用开发人员工具直接查看它并查看其属性,并且可以编写JavaScript代码直接访问它,而无需解析JSON或XML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM