我试图通过在Django中传递坐标列表在谷歌地图上放置多个标记。但是当呈现页面时,没有标记存在。任何人都可以帮我指出我的代码中的问题:
Html代码:
<script>
{{ coordinatelist }}
var map;
function initMap() {
// Constructor creates a new map - only center and zoom are required.
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 40, lng:0},
zoom:1,
minZoom:1
});
}
{% for item in coordinatelist %}
var latlongcoordinates = new google.maps.LatLng({{ item.0 }},{{ item.1 }});
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
var marker1 = new google.maps.Marker({
position: he,
title:"Mymarker"});
marker1.setMap(map);
{% endfor %}
生成的Javascript:
[[39.095963, -108.193359], [44.150681, -93.251953]]
var map;
function initMap() {
// Constructor creates a new map - only center and zoom are required.
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 40, lng:0},
zoom:1,
minZoom:1
});
}
var he = new google.maps.LatLng(39.095963,-108.193359);
var marker=new google.maps.Marker({
position: he,
title:"Mymarker"});
marker.setMap(map);
var he = new google.maps.LatLng(44.150681,-93.251953);
var marker=new google.maps.Marker({
position: he,
title:"Mymarker"});
marker.setMap(map)