简体   繁体   English

通过json在Google地图上添加标记

[英]adding marker on a google map via json

This is my script taking from this tutorial (google). 这是本教程 (google)中的脚本。 I can't show the marker on the map. 我无法在地图上显示标记。 I try to alert any data that Json receive but it doesn't popup. 我尝试提醒Json收到的任何数据,但不会弹出。 I do not get an error in my firebug inspector so that I could have at leat a clue. 我的萤火虫检查器没有出现错误,因此可以从中得到一些提示。

<script type="text/javascript">
    $( document ).ready(function() {

$('#map_canvas').gmap().bind('init', function() { 
    $.getJSON( 'http://jquery-ui-map.googlecode.com/svn/trunk/demos/json/demo.json', function(data) { 
        $.each( data.markers, function(i, marker) {
            alert(marker.latitude);

            $('#map_canvas').gmap('addMarker', { 
                'position': new google.maps.LatLng(marker.latitude, marker.longitude), 
                'bounds': true 
            }).click(function() {
                $('#map_canvas').gmap('openInfoWindow', { 'content': marker.content }, this);
            });

        });
    });
});

});
    </script>

You can't access files from a different domain(except they send appropriate headers, what isn't the case for this file ) via ajax. 您无法通过ajax访问其他域中的文件(除非它们发送适当的标头,但该文件不是这种情况)。 Download the demo.json and place it on your own server/domain. 下载demo.json并将其放在您自己的服务器/域上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM