English 中文(简体)
添加谷歌地图标记,在贾瓦特有DJango Template Tags
原标题:Adding Google Map Markers with DJango Template Tags in Javascript

我正试图在地图上增加一个地图标数,使用Django模板标数作为纬度和长度,但事情进展太快。 我认为,这里是“javascript”法典。 我把该守则装在一份外部联合材料中。 在这方面,我必须首先着手进行所有工作。 同样,当我这样做时,甚至没有看到更多东西。 它失踪。

 function initialize() {
            var latLng = new google.maps.LatLng(41.85, -87.65);

            map = new google.maps.Map(document.getElementById( map_canvas ), {
                zoom: 8,
                center: latLng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            });



             marker = new google.maps.Marker({
                position: latLng,
                title:  Point A ,
                map: map,
                draggable: true
            });

            // Update current position inf o and load in markers from database
            loadMarkers();
            updateMarkerPosition(latLng);
            geocodePosition(latLng);

这里是装货者所认为的。

            function loadMarkers(){
            {% for mark in latest_marks %}
            var point = new google.maps.LatLng({{mark.lat}},{{mark.lng}});
                var marker = new google.maps.Marker({
                position: point,
                map: map,
            });
            {% endfor %}    
        }

希望得到任何帮助。 乘客。

最佳回答

你们可以把Django模板标贴在外部javascript文档中。 Django甚至看不到。 你的网络服务器直接为客户服务。

What you can do is use Django to generate Javascript variables and data structures, e.g. inside <script> tags in your template, and then your external javascript files can reference those just fine.

例如,在你的模板中,你可以产生Django:

<script>var myVar = {something: 42};</script>

然后,您的外部javascript文档可使用myVar。 我做了很多工作,以适应外部javascript的行为。

正如我在评论中提到的,你有一条线 trail:<条码>:地图、。 这将产生错误,并停止你的文字。

问题回答

很可能,你在“javascript”守则中出现错误,从而阻止了“gogle”地图 a的执行。 你的法典确实很容易发现javascript错误:正如Brian Neal所指出的,字面字面上的字句与纸面上的字面非常相似,但有一个微妙的区别:

虽然在最后一项要素之后,假装允许额外 com,但 j除外。

这部建筑在:

{ 
    position : point, 
    map : map, 
}

但是,在javascript中,这没有发生yn子错误:

{ 
   position: point, 
   map: map, 
}

这是一次尝试。

Every modern web browser has decent javascript debugging resources. Chrome has a very nice one, and Firefox has firebug (last incarnations of IE are also quite decent). If you need further help, look at the javascript console and tell us what errors are you seeing.

[编辑]

为了对“django”模板标签进行解释,你必须从“django”的角度而不是从静态档案中为你的javscript文档服务。

ur鱼的条目:

      (r jsresources/latest_points.js ,  yourappname.views.latest_points ) 

页: 1 ::

def latest_points(request):
    latest_points = YourPointsModel.objects.order_by( -id )[100]
    return render_to_response( latest_points.js , locals(), mimetype= text/javascript )




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签