Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps 不使用javascript api显示google direction web服务的结果_Google Maps_Google Maps Api 3_Map Directions - Fatal编程技术网

Google maps 不使用javascript api显示google direction web服务的结果

Google maps 不使用javascript api显示google direction web服务的结果,google-maps,google-maps-api-3,map-directions,Google Maps,Google Maps Api 3,Map Directions,我正在开发一个应用程序,可以在两点之间找到方向,显示在谷歌地图上,并将其存储在服务器端,这样我可以在需要时再次渲染,以便将一条路线与另一条路线进行比较。 我已成功使用查找路线,我还使用查找路线并使用在地图上显示。 这两个服务都返回类似的JSON,但JSON属性的名称不同(请参见下面的示例1)。更重要的是,JSAPI从一个调用返回lat/lng的不同属性名称(参见下面的示例2)。 因此,问题是我无法使用从服务器端web服务调用获得的JSON并直接将其传递给javascripts Direction

我正在开发一个应用程序,可以在两点之间找到方向,显示在谷歌地图上,并将其存储在服务器端,这样我可以在需要时再次渲染,以便将一条路线与另一条路线进行比较。
我已成功使用查找路线,我还使用查找路线并使用在地图上显示。
这两个服务都返回类似的JSON,但JSON属性的名称不同(请参见下面的示例1)。更重要的是,JSAPI从一个调用返回lat/lng的不同属性名称(参见下面的示例2)。

因此,问题是我无法使用从服务器端web服务调用获得的JSON并直接将其传递给javascripts DirectionRenderer类以显示路由。此外,每次我在地图上显示路线时,我都必须进行JS调用。这将导致不必要地使用我的配额。有没有更好的办法。我已经回答了以下问题,但实际上我无法得到答案

例1:

网络服务呼叫结果:

{
    "routes" : [
      {
         "bounds" : {
            "northeast" : {
               "lat" : 12.9198217,
               "lng" : 77.6124895
            },
            "southwest" : {
               "lat" : 12.912811,
               "lng" : 77.60924989999999
            }
         },
          .....
{
"routes": [
    {
        "bounds": {
            "ta": {
                "d": 12.91281,
                "b": 12.919820000000001
            },
            "ga": {
                "b": 77.60925,
                "d": 77.61249000000001
            }
        },
        ......
        "path": [
                            {
                                "d": 12.913920000000001,
                                "e": 77.60928000000001
                            },
                            {
                                "d": 12.913960000000001,
                                "e": 77.60958000000001
                            },
                            {
                                "d": 12.91398,
                                "e": 77.61
                            }
                        ],
                        ..........
{
"routes": [
    {
        "bounds": {
            "Aa": {
                "k": 12.91281,
                "j": 12.919820000000001
            },
            "qa": {
                "j": 77.60925,
                "k": 77.61249000000001
            }
        },
        .....
        "path": [
                            {
                                "k": 12.91281,
                                "A": 77.60925
                            },
                            {
                                "k": 12.913920000000001,
                                "A": 77.60928000000001
                            }
                        ],
                        .........
这没有“路径”属性

Javascript V3调用结果:

{
    "routes" : [
      {
         "bounds" : {
            "northeast" : {
               "lat" : 12.9198217,
               "lng" : 77.6124895
            },
            "southwest" : {
               "lat" : 12.912811,
               "lng" : 77.60924989999999
            }
         },
          .....
{
"routes": [
    {
        "bounds": {
            "ta": {
                "d": 12.91281,
                "b": 12.919820000000001
            },
            "ga": {
                "b": 77.60925,
                "d": 77.61249000000001
            }
        },
        ......
        "path": [
                            {
                                "d": 12.913920000000001,
                                "e": 77.60928000000001
                            },
                            {
                                "d": 12.913960000000001,
                                "e": 77.60958000000001
                            },
                            {
                                "d": 12.91398,
                                "e": 77.61
                            }
                        ],
                        ..........
{
"routes": [
    {
        "bounds": {
            "Aa": {
                "k": 12.91281,
                "j": 12.919820000000001
            },
            "qa": {
                "j": 77.60925,
                "k": 77.61249000000001
            }
        },
        .....
        "path": [
                            {
                                "k": 12.91281,
                                "A": 77.60925
                            },
                            {
                                "k": 12.913920000000001,
                                "A": 77.60928000000001
                            }
                        ],
                        .........
例2: 另一个Javascript V3调用结果:

{
    "routes" : [
      {
         "bounds" : {
            "northeast" : {
               "lat" : 12.9198217,
               "lng" : 77.6124895
            },
            "southwest" : {
               "lat" : 12.912811,
               "lng" : 77.60924989999999
            }
         },
          .....
{
"routes": [
    {
        "bounds": {
            "ta": {
                "d": 12.91281,
                "b": 12.919820000000001
            },
            "ga": {
                "b": 77.60925,
                "d": 77.61249000000001
            }
        },
        ......
        "path": [
                            {
                                "d": 12.913920000000001,
                                "e": 77.60928000000001
                            },
                            {
                                "d": 12.913960000000001,
                                "e": 77.60958000000001
                            },
                            {
                                "d": 12.91398,
                                "e": 77.61
                            }
                        ],
                        ..........
{
"routes": [
    {
        "bounds": {
            "Aa": {
                "k": 12.91281,
                "j": 12.919820000000001
            },
            "qa": {
                "j": 77.60925,
                "k": 77.61249000000001
            }
        },
        .....
        "path": [
                            {
                                "k": 12.91281,
                                "A": 77.60925
                            },
                            {
                                "k": 12.913920000000001,
                                "A": 77.60928000000001
                            }
                        ],
                        .........

你可以这样做,但有几个陷阱

首先,确保您的应用程序符合第10.5.d点:

与来自Directions API web服务的JSON响应不同(该服务具有一致的命名字段),来自JavaScript Directions服务的JSON响应不需要解析。相反,您需要以JavaScript对象的形式访问
DirectionsResult
对象,该对象包含
google.maps.LatLng
对象,例如
routes[0]。legs[0]。steps[0]。start_location

对于从Directions API web服务获得的路由,有几种方法可以在JavaScript API上显示它。我的首选是将JSON响应“翻译”为
DirectionsResult
对象。您可以在服务器上或在JavaScript中执行此操作,但我认为前者更好


或者,您可以重新查询方向服务(使用JavaScript服务)以再次获取路线。这不仅会消耗额外的配额,还可能返回不同的(更为最新的)路线。这是好是坏,取决于你想要什么。

我需要包括任何其他细节吗?为什么我没有得到任何回应?嗨,你能让它工作吗?