Django地理位置映射字段问题-GeopositionField()模型
我使用了django-geoposition来标记我模型的位置。一切都很好,然后我尝试通过管理员界面添加模型,我可以在管理员界面看到地图。但是,当我尝试在模板中显示位置字段时,我在页面上看到一个灰色的方块,原本应该是地图的地方。我不知道为什么会出现这个问题。我使用的是django 1.6。
我在我的模板中使用了从文档中复制的代码:
{% extends "main.html" %}
{% block content %}
{{ instance.position.latitude }}
{{ instance.position.longitude }}
<div id="map-canvas"></div>
<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
<script>
function initialize() {
var map = new google.maps.Map(document.getElementById('map-canvas'));
var bounds = new google.maps.LatLngBounds();
function addMarker(lat, lng, title) {
var position = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({
position: position,
map: map,
title: title
});
bounds.extend(position);
}
addMarker({{ instance.position.latitude }}, {{ instance.position.longitude }}, "{{ instance.adress }}");
map.fitBounds(bounds);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
{% endblock %}
2 个回答
0
你可以试试:
{% load l10n %}
{% localize off %}
{{ instance.position.latitude }},
{{ instance.position.longitude }}
{% endlocalize %}
或者只用:
{{ instance.position }}
这包括了经度和纬度
0
问题出在你的settings.py文件里。把语言代码改成en-US,就应该能正常工作了。