2012-06-01 32 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

得到了同样的错误。 –

相关问题