Json 我们可以在谷歌地图上绘制自定义路线吗?

Json 我们可以在谷歌地图上绘制自定义路线吗?,json,c#-4.0,google-maps-api-3,geojson,directions,Json,C# 4.0,Google Maps Api 3,Geojson,Directions,我正在探索谷歌地图API。我有一个web服务,它返回GeoJSON对象作为响应。我想在谷歌地图上渲染它。我尝试了以下API directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); 这为我们提供了给定st

我正在探索谷歌地图API。我有一个web服务,它返回GeoJSON对象作为响应。我想在谷歌地图上渲染它。我尝试了以下API

directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    }
  });
这为我们提供了给定start和end-in-request参数的GeoJSON。我试图从我的服务中获取GeoJSON响应,而不是Google数据,我试图呈现我自己的响应

从我的定制服务返回的数据与谷歌的格式相同

Google服务返回的数据格式如下 我已经构建了与Google DirectionsService响应相同的对象

请查看下面的详细信息;

“路线”:[{“边界”:{“东北”:{“拉特”:30.2844454,“液化天然气”:-97.7040698},“西南”:{“拉特”:30.2121885,“液化天然气”:-97.7506593},“版权”:“地图” 数据©2014谷歌“腿”:……步骤……}

编辑: 我用addGeoJson()API尝试了另一个选项

我使用的JSON字符串由jsonlint验证。

类似这样的东西

directionsDisplay = new google.maps.DirectionsRenderer();
var Basingstoke = new google.maps.LatLng(51.2949612, -1.0643864);
var mapOptions = {
  zoom:7,
  center: Basingstoke
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
directionsDisplay.setMap(map);

var point1 = new google.maps.LatLng(51.2941293,-0.9139252);
var point2 = new google.maps.LatLng(51.3250339,-0.8050919);

var wps = [{ location: point1 }, { location: point2 }];

var org = new google.maps.LatLng ( 51.2949612, -1.0643864);
var dest = new google.maps.LatLng ( 52.3069282, -0.7540226);

var request = {
        origin: org,
        destination: dest,
        waypoints: wps,
        durationInTraffic: true,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
        };


directionsService = new google.maps.DirectionsService();
directionsService.route(request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                var newRoute = response.routes[0].legs[2].duration.value;
                directionsDisplay.setDirections(response);
                alert ('Travel Time: ' + newRoute + ' seconds');
            }
            else
                alert ('failed to get directions');
        });


}

google.maps.event.addDomListener(window, 'load', initialize);

有问题吗?你的数据是什么样子的?当你说“从我的定制服务返回的数据与谷歌的格式相同”是什么意思?您说您的格式是GeoJSON;DirectionsService不返回GeoJSON。@geocodezip-请查找有问题的更新。它的可能副本与Google示例类似。我试图使用自定义数据,而不是Google服务返回的数据。
directionsDisplay = new google.maps.DirectionsRenderer();
var Basingstoke = new google.maps.LatLng(51.2949612, -1.0643864);
var mapOptions = {
  zoom:7,
  center: Basingstoke
}
map = new google.maps.Map(document.getElementById('map'), mapOptions);
directionsDisplay.setMap(map);

var point1 = new google.maps.LatLng(51.2941293,-0.9139252);
var point2 = new google.maps.LatLng(51.3250339,-0.8050919);

var wps = [{ location: point1 }, { location: point2 }];

var org = new google.maps.LatLng ( 51.2949612, -1.0643864);
var dest = new google.maps.LatLng ( 52.3069282, -0.7540226);

var request = {
        origin: org,
        destination: dest,
        waypoints: wps,
        durationInTraffic: true,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
        };


directionsService = new google.maps.DirectionsService();
directionsService.route(request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                var newRoute = response.routes[0].legs[2].duration.value;
                directionsDisplay.setDirections(response);
                alert ('Travel Time: ' + newRoute + ' seconds');
            }
            else
                alert ('failed to get directions');
        });


}

google.maps.event.addDomListener(window, 'load', initialize);