2015-06-26 20 views
-1

嘗試做多引腳與超時,所以它看起來涼爽,但它不工作要引導下探地圖引腳與超時

我認爲故障可能是在地圖作爲家庭或一個簡單的VAR定義問題什麼的分配你可以看到這些讓我知道。我認爲動畫應該很酷,按鈕方法應該確保你看到它,而不是在你向下滾動到足以看到它之前已經下降。成才壞壽

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="utf-8"> 
    <title>LANDMARK LOCATIONS <code>setTimeout()</code></title> 
    <style> 
     #map-canvas { 
     width: 100%; 
     height: 400px; 
     } 

    </style> 
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script> 
    <script> 
     var home = new google.maps.LatLng(39.9176356,-99.3003073); 

var neighborhoods = [ 
    new google.maps.LatLng(46.448114-96.736079), 
new google.maps.LatLng(45.46104-98.488264), 
new google.maps.LatLng(45.460888-98.498119), 
new google.maps.LatLng(44.363302-97.134493), 
new google.maps.LatLng(43.760871-96.778317), 
new google.maps.LatLng(46.888705-103.194951), 
new google.maps.LatLng(44.670711-103.850721), 
new google.maps.LatLng(43.839003-101.283079), 
new google.maps.LatLng(46.832538-100.76937), 
new google.maps.LatLng(46.836574-100.781966), 
new google.maps.LatLng(30.325508-96.157669), 
new google.maps.LatLng(39.094627-94.437796), 
new google.maps.LatLng(31.0451-97.165565) 
]; 

var markers = []; 
var map; 

function initialize() { 
    var mapOptions = { 
    zoom: 4, 
    center: home 
    }; 

    map = new google.maps.Map(document.getElementById('map-canvas'), 
      mapOptions); 
} 

function drop() { 
    clearMarkers(); 
    for (var i = 0; i < neighborhoods.length; i++) { 
    addMarkerWithTimeout(neighborhoods[i], i * 200); 
    } 
} 

function addMarkerWithTimeout(position, timeout) { 
    window.setTimeout(function() { 
    markers.push(new google.maps.Marker({ 
     position: position, 
     map: map, 
     animation: google.maps.Animation.DROP 
    })); 
    }, timeout); 
} 

function clearMarkers() { 
    for (var i = 0; i < markers.length; i++) { 
    markers[i].setMap(null); 
    } 
    markers = []; 
} 

google.maps.event.addDomListener(window, 'load', initialize); 
    </script> 
    </head> 
    <body> 
    <div id="panel" style="margin-left: 42%"> 
     <button id="drop" onclick="drop()">Drop LANDMarkers</button> 
    </div> 
    <div id="map-canvas"></div> 
    </body> 
</html> 

回答

0

你有錯別字在你的代碼(缺少逗號,一個google.maps.LatLng需要兩個參數):

var neighborhoods = [ 
new google.maps.LatLng(46.448114-96.736079), 
new google.maps.LatLng(45.46104-98.488264), 
new google.maps.LatLng(45.460888-98.498119), 
new google.maps.LatLng(44.363302-97.134493), 
new google.maps.LatLng(43.760871-96.778317), 
new google.maps.LatLng(46.888705-103.194951), 
new google.maps.LatLng(44.670711-103.850721), 
new google.maps.LatLng(43.839003-101.283079), 
new google.maps.LatLng(46.832538-100.76937), 
new google.maps.LatLng(46.836574-100.781966), 
new google.maps.LatLng(30.325508-96.157669), 
new google.maps.LatLng(39.094627-94.437796), 
new google.maps.LatLng(31.0451-97.165565)]; 

應該是:

var neighborhoods = [ 
new google.maps.LatLng(46.448114,-96.736079), 
new google.maps.LatLng(45.46104,-98.488264), 
new google.maps.LatLng(45.460888, -98.498119), 
new google.maps.LatLng(44.363302, -97.134493), 
new google.maps.LatLng(43.760871, -96.778317), 
new google.maps.LatLng(46.888705, -103.194951), 
new google.maps.LatLng(44.670711, -103.850721), 
new google.maps.LatLng(43.839003, -101.283079), 
new google.maps.LatLng(46.832538, -100.76937), 
new google.maps.LatLng(46.836574, -100.781966), 
new google.maps.LatLng(30.325508, -96.157669), 
new google.maps.LatLng(39.094627, -94.437796), 
new google.maps.LatLng(31.0451, -97.165565)]; 

working fiddle

+0

ARGH我知道這將是一件簡單的事情,我甚至沒有想過看看LatLng,我認爲它會晚些時候......謝謝SOOOOO much- –