Google Map Directions Example

Google_Map_Directions_Example

Google Map 中的路徑規劃範例,除了起始點與目的點外,利用陣列一次丟最多不超過8個點,並且不使用最佳路徑。

// Code by Rchockxm
var c_lat = 24.24814670;
var c_lng = 120.71403060;
var c_latlng = new google.maps.LatLng(c_lat, c_lng);    
var c_mapOptions = {
    zoom: 15,
    scaleControl: true,            
    mapTypeId: google.maps.MapTypeId.ROADMAP
};   
    
var c_map = new google.maps.Map(document.getElementById("map_canvas"), c_mapOptions);   
var c_directionsDisplay = new google.maps.DirectionsRenderer();
c_directionsDisplay.setMap(c_map);   
c_directionsDisplay.setPanel(document.getElementById("directionsPanel"));
         
var c_start = c_latlng;
var c_end = c_latlng; 
var c_waypts = [];    
var c_length = (gt_arrays.length>8) ? 8 : gt_arrays.length-1;    
if (gt_arrays.length>=1) {   
    for (var i=0; i<=c_length; i++) {            
        c_waypts.push({
            location: gt_arrays[i],
            stopover: true
        }); 
    }  
}  
    
var c_directionsServiceOptions = {
    origin: c_start,
    destination: c_end,
    waypoints: c_waypts,
    optimizeWaypoints: false,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
};      
var c_directionsService = new google.maps.DirectionsService();   
c_directionsService.route(c_directionsServiceOptions, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        c_directionsDisplay.setDirections(response);
    }
}); 

檔案下載: 圖一

- CRC32: 293FC3F1
- MD5: 91761DFBCBA0C80F18B3057CE357A524
- SHA-1: 62AB5ABCAD254CBE9CD0DBD970F3DE09D02EB038

Silence Unlimited Download#1
Silence Unlimited Download#2

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

你可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>