在GMAP V3 API上绘制多条路线,还在地图上绘制超过10个点?

时间:2011-08-18 05:23:36

标签: javascript google-maps google-maps-api-3

我尝试在GMAP v3 API上添加多个路由,但不显示所有路由。我已将alert放在$directionsDisplay.setDirections(response)之前,然后显示所有路线......

此外,我想在路线中添加超过10个点。

源代码

function drawRouteMap()
    {
            var route_id = $(".route_detail").val();    
    $.ajax({  
                                        url: '<?php echo ROOTURL."module/tp2/Main.php?do=tp_gmap_ajax&no_doc_type=1"?>',  
                                       dataType: 'json',  
                                       type: 'POST',
                                       data: {all_stop_lat_log:'all_stop_lat_log',route_id:route_id},  
                                       async: false,  
                                       success:function(data){                                              
            if(data) {  
                var subroute_route_arr = [];
                var subroute_arr_count = 0;
                var no_of_point_in_subroute =8 ;

                var total_subroute_count = Math.ceil(parseFloat(data.length/no_of_point_in_subroute));

                    for(subroute_arr_count ; subroute_arr_count < total_subroute_count ; subroute_arr_count++)
                    {
                            var waypts = [] ;
                            var loop_count_start = subroute_arr_count * no_of_point_in_subroute  ;


                            var loop_count_end = loop_count_start+no_of_point_in_subroute;
                            var loop_count_start_val =  loop_count_start +1;
                                var loop_count_end_val = loop_count_start;                          


                            for(loop_count_start_val; loop_count_start_val<=loop_count_end; loop_count_start_val++)
                            {   
                                if(data[loop_count_start_val] != undefined){
                                    var loop_rec_latt = data[loop_count_start_val].stop_latt;
                                    var loop_rec_lang = data[loop_count_start_val].stop_lang;
                                    loop_count_end_val++;
                                    waypts.push({location:new google.maps.LatLng(loop_rec_latt,loop_rec_lang),stopover:true});  
                                } else {  
                                    break;
                                }

                            } 


                        alert('hi...'); //// **if this alert is removed then correct routes not displayed , by keeping the alert box only correct route is displayed,even by keeping some sort of delay instead of alert..then the correct route is not displayed....**


                    var origin_point_latt = data[loop_count_start].stop_latt;
                    var origin_point_lang = data[loop_count_start].stop_lang;

                    var destination_point_latt = data[loop_count_end_val].stop_latt;
                    var destination_point_lang = data[loop_count_end_val].stop_lang;


                                var request = {
    origin: new google.maps.LatLng(origin_point_latt,origin_point_lang), 
    destination: new google.maps.LatLng(destination_point_latt,destination_point_lang),
                                waypoints: waypts,
                                optimizeWaypoints:false,
                                travelMode: google.maps.DirectionsTravelMode.DRIVING
                            }; 

                             $directionsService_arr[subroute_arr_count].route(request, function(response, status) {
                              if (status == google.maps.DirectionsStatus.OK) {
                                $directionsDisplay_arr[subroute_arr_count].setDirections(response); 

                                }
                            }); 

                    }       


                                            } 
                                        removeAllMarkerEvent();                                                     
                                        setAllMarkerEvent();
                                        }
                                });




    }

function drawRouteMap() { var route_id = $(".route_detail").val(); $.ajax({ url: '<?php echo ROOTURL."module/tp2/Main.php?do=tp_gmap_ajax&no_doc_type=1"?>', dataType: 'json', type: 'POST', data: {all_stop_lat_log:'all_stop_lat_log',route_id:route_id}, async: false, success:function(data){ if(data) { var subroute_route_arr = []; var subroute_arr_count = 0; var no_of_point_in_subroute =8 ; var total_subroute_count = Math.ceil(parseFloat(data.length/no_of_point_in_subroute)); for(subroute_arr_count ; subroute_arr_count < total_subroute_count ; subroute_arr_count++) { var waypts = [] ; var loop_count_start = subroute_arr_count * no_of_point_in_subroute ; var loop_count_end = loop_count_start+no_of_point_in_subroute; var loop_count_start_val = loop_count_start +1; var loop_count_end_val = loop_count_start; for(loop_count_start_val; loop_count_start_val<=loop_count_end; loop_count_start_val++) { if(data[loop_count_start_val] != undefined){ var loop_rec_latt = data[loop_count_start_val].stop_latt; var loop_rec_lang = data[loop_count_start_val].stop_lang; loop_count_end_val++; waypts.push({location:new google.maps.LatLng(loop_rec_latt,loop_rec_lang),stopover:true}); } else { break; } } alert('hi...'); //// **if this alert is removed then correct routes not displayed , by keeping the alert box only correct route is displayed,even by keeping some sort of delay instead of alert..then the correct route is not displayed....** var origin_point_latt = data[loop_count_start].stop_latt; var origin_point_lang = data[loop_count_start].stop_lang; var destination_point_latt = data[loop_count_end_val].stop_latt; var destination_point_lang = data[loop_count_end_val].stop_lang; var request = { origin: new google.maps.LatLng(origin_point_latt,origin_point_lang), destination: new google.maps.LatLng(destination_point_latt,destination_point_lang), waypoints: waypts, optimizeWaypoints:false, travelMode: google.maps.DirectionsTravelMode.DRIVING }; $directionsService_arr[subroute_arr_count].route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { $directionsDisplay_arr[subroute_arr_count].setDirections(response); } }); } } removeAllMarkerEvent(); setAllMarkerEvent(); } }); }

1 个答案:

答案 0 :(得分:0)

在谷歌地图路线中,您只能拥有8个航点和1个起点和终点。 当你想要的东西超过你必须支付的时候