在Google地图上放置标记时发生循环错误的JavaScript
接近解决一个三天的问题。我试图使用长期存储在Django模型中的lat在Google地图上放置标记。我以前从未使用过AJAX,但我正试图这样做来实现这一点。使用Firebug,它表明我在JavaScript中有一个for循环错误,尽管我通常是这样的(JavaScript的新版本)。源代码显示了lat,longs向上拉,尽管我通常认为格式是完美的(以逗号结尾) 如果有人发现错误,代码如下。非常感谢您的洞察力:在Google地图上放置标记时发生循环错误的JavaScript,javascript,ajax,google-maps-markers,Javascript,Ajax,Google Maps Markers,接近解决一个三天的问题。我试图使用长期存储在Django模型中的lat在Google地图上放置标记。我以前从未使用过AJAX,但我正试图这样做来实现这一点。使用Firebug,它表明我在JavaScript中有一个for循环错误,尽管我通常是这样的(JavaScript的新版本)。源代码显示了lat,longs向上拉,尽管我通常认为格式是完美的(以逗号结尾) 如果有人发现错误,代码如下。非常感谢您的洞察力: <script> function mainGeo() {
<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>
函数mainGeo()
{
if(导航器.地理位置)
{
getCurrentPosition(mainMap,错误,{maximumAge:30000,超时:10000,enableHighAccurance:true});
}
其他的
{
警报(“抱歉,您的浏览器似乎不支持地理位置。”);
}
}
var映射;
功能主地图(位置)
{
//将坐标定义为Google Maps LatLng对象
var coords=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
//准备地图选项
var映射选项=
{
缩放:15,
中心:coords,
mapTypeControl:false,
navigationControlOptions:{style:google.maps.NavigationControlStyle.SMALL},
mapTypeId:google.maps.mapTypeId.ROADMAP
};
//创建地图,并将其放置在map_canvas div中
map=new google.maps.map(document.getElementById(“map_canvas”),mapOptions);
//放置初始标记
var marker=new google.maps.marker({
职位:coords,
地图:地图,
标题:“您当前的位置!”
});
}
函数错误(){
警报(“您已拒绝显示您的位置。您将无法提交故事。”);
}
mainGeo();
var stories=[{%forstories%}
{纬度:{{故事.纬度},经度:{{故事.经度},{%endfor%}];
装载标记(故事);
函数加载标记(故事)
for(故事中的变量s){
var story=story[s];
var point=new google.maps.LatLng(story.lation,story.longitude);
var marker=new google.maps.marker({position:point,map:map});
}
可能是说var story=story[s]代码>应该是var story=stories[s]代码>