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
Javascript 谷歌地图API:方向结果未显示_Javascript_Google Maps_Directions - Fatal编程技术网

Javascript 谷歌地图API:方向结果未显示

Javascript 谷歌地图API:方向结果未显示,javascript,google-maps,directions,Javascript,Google Maps,Directions,我正在使用GoogleMapsJSAPI创建我自己的样式地图。我想在地图中添加方向功能,我遵循了(显示方向结果标题下),但最终路线没有出现 我调试了我的代码,发现比directionsService.route函数返回google.maps.DirectionsStatus.OK和directionsDisplay.setDirections(result)调用时没有JS错误。。。因此,方向计算成功,但没有显示在我的地图上。A试图关闭特殊地图样式,但即使在默认地图样式下,它也不会出现。你知道问题

我正在使用GoogleMapsJSAPI创建我自己的样式地图。我想在地图中添加方向功能,我遵循了(显示方向结果标题下),但最终路线没有出现

我调试了我的代码,发现比directionsService.route函数返回google.maps.DirectionsStatus.OKdirectionsDisplay.setDirections(result)调用时没有JS错误。。。因此,方向计算成功,但没有显示在我的地图上。A试图关闭特殊地图样式,但即使在默认地图样式下,它也不会出现。你知道问题出在哪里吗

好的,一些代码…:

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAB2gbXmG... ...mNs66iPr8&amp;sensor=false&amp;callback=directions_init"></script>

    <script type="text/javascript">
        var map;
        var zoom = 11;
        var directionsDisplay;
        var directionsService;

        function gmap_init(){
            var styleArray = [ /*here is style but even if its commented its not working*/];

            var alterMapStyle = new google.maps.StyledMapType(styleArray, {name: "ALTER style"});


            var latlng = new google.maps.LatLng(/*lat, lng*/);
            var myOptions = {
              zoom: zoom,
              center: latlng,
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              mapTypeControl: false,
              panControl: false,
              zoomControl: false,
              scaleControl: false,
              streetViewControl: false
            };
            map = new google.maps.Map(document.getElementById("gmap"), myOptions);

            map.mapTypes.set('ALTER_style', alterMapStyle);
            map.setMapTypeId('ALTER_style');


        }

        function directions_init(){

            directionsService = new google.maps.DirectionsService();
            directionsDisplay = new google.maps.DirectionsRenderer();
            directionsDisplay.setMap(map);

            display_route();

        }

        function display_route(){
            var request = {
                origin: 'Place A',
                destination:'Place B',
                travelMode: google.maps.TravelMode.DRIVING
              };

          directionsService.route(request, function(result, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                //program got here without error
                directionsDisplay.setDirections(result);
            }
          });

        }

var映射;
var=11;
var方向显示;
var定向服务;
函数gmap_init(){
var styleArray=[/*这里是样式,但即使其注释了,也不起作用*/];
var alterMapStyle=new google.maps.StyledMapType(styleArray,{name:“ALTER style”});
var latlng=new google.maps.latlng(/*lat,lng*/);
变量myOptions={
缩放:缩放,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP,
mapTypeControl:false,
泛控制:错误,
动物控制:错误,
scaleControl:false,
街景控制:错误
};
map=新的google.maps.map(document.getElementById(“gmap”),myOptions);
map.mapTypes.set('ALTER_style',altermaptyple);
setMapTypeId('ALTER_style');
}
函数方向_init(){
directionsService=new google.maps.directionsService();
directionsDisplay=new google.maps.DirectionsRenderer();
方向显示.setMap(地图);
显示路径();
}
功能显示_路线(){
var请求={
来源:“地点A”,
目的地:'Place B',
travelMode:google.maps.travelMode.DRIVING
};
路由(请求、功能(结果、状态){
if(status==google.maps.directionstatus.OK){
//程序顺利到达这里
方向显示。设置方向(结果);
}
});
}

不确定这是否是您问题的根源,但值得一试。。。 从脚本输入

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAB2gbXmG... ...mNs66iPr8&amp;sensor=false&amp;callback=directions_init"></script> 
尝试从gmap_init调用directions_init,或者在onload后触发的任何事件上调用directions_init

directionsDisplay.setMap(null);