2012-06-01 50 views
0

接近解決爲期三天的問題。我試圖在Google Map上使用經緯度放置在Django模型中的標記。我從來沒有使用過AJAX,但我正在嘗試這樣做。使用Firebug,它表明我在JavaScript中有一個for循環錯誤,儘管我很喜歡它是什麼(在JavaScript中是新的)。來源顯示拉特,拉長了,儘管我很喜歡格式是完美的(以逗號結尾)。用於在Google地圖上放置標記的循環錯誤的JavaScript

如果有人發現錯誤,代碼如下。洞察大加讚賞:

<script> 
function mainGeo() 
    { 
     if (navigator.geolocation) 
      { 
       navigator.geolocation.getCurrentPosition(mainMap, error, {maximumAge: 30000, timeout: 10000, enableHighAccuracy: true}); 
     } 
     else 
     { 
       alert("Sorry, but it looks like your browser does not support geolocation."); 
     } 
    } 




var map; 



function mainMap(position) 
{ 
     // Define the coordinates as a Google Maps LatLng Object 
     var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 

     // Prepare the map options 
     var mapOptions = 
     { 
        zoom: 15, 
        center: coords, 
        mapTypeControl: false, 
        navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}, 
        mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 

     // Create the map, and place it in the map_canvas div 
     map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 

     // Place the initial marker 
     var marker = new google.maps.Marker({ 
        position: coords, 
        map: map, 
        title: "Your current location!" 
     }); 
    } 


function error() { 
     alert("You have refused to display your location. You will not be able to submit stories."); 
     } 

mainGeo(); 

var stories = [{% for story in stories %} 
      {latitude:{{story.latitude}},longitude:{{story.longitude}}}, {% endfor %}]; 


loadMarkers(stories); 

function loadMarkers(stories) 
    for (var s in stories) { 
     var story = story[s]; 
     var point = new google.maps.LatLng(story.latitude, story.longitude); 
     var marker = new google.maps.Marker({position: point, map: map}); 
    } 



</script> 

回答

0

也許行說var story = story[s];應該var story = stories[s];

+0

得到了同樣的錯誤。 –

相關問題