【问题标题】:Sending map boundary via Jquery to google maps ui通过 Jquery 将地图边界发送到谷歌地图 ui
【发布时间】:2013-11-25 16:10:46
【问题描述】:

我使用这个脚本来获取带有 JSON 的谷歌地图的标记。 它不起作用,因为我需要像这样在 Json 脚本中接收边界:

$swLat=$_GET["swLat"];
$swLon=$_GET["swLon"];

$neLat=$_GET["neLat"];
$neLon=$_GET["neLon"];

这就是我需要你帮助的地方。

谷歌地图脚本

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="http://skiweather.eu/gmap3/js/jquery.ui.map.js"></script>

<script language="javascript" type="text/javascript">
        var map = null;
map = new google.maps.Map(document.getElementById("map"));
        var markers = new Array();

        var bounds = map.getBounds();
        var zoomLevel = map.getZoom();           


     $(function() { 

    demo.add(function() {

    $('#map').gmap().bind('init', function() { 
        $.getJSON( 'http://skiweather.eu/gmap3/markers/index.php', {zoom: zoomLevel, 
            swLat: bounds.getSouthWest().lat(), swLon: bounds.getSouthWest().lng(), 
            neLat: bounds.getNorthEast().lat(), neLon: bounds.getNorthEast().lng()}, function(data) { 
            $.each( data.markers, function(i, marker) {
                $('#map').gmap('addMarker', { 
                    'position': new google.maps.LatLng(marker.latitude, marker.longitude), 
                    'bounds': true 
                }).click(function() {
                    $('#map').gmap('openInfoWindow', { 'content': marker.content }, this);
                });
            });
        });
    });

    }).load();


    }); 


                    </script>

                </head>
                <body>
                <div id="map"></div>

【问题讨论】:

    标签: php jquery google-maps google-maps-api-3


    【解决方案1】:

    您的代码中的 jQuery/gmap 部分根本不会被执行。

    固定代码:

    <script type="text/javascript">
       $(function() { 
        $('#map').gmap().bind('init', function() {
          var markers = new Array();
          var bounds = $(this).gmap('get','map').getBounds();
          var zoomLevel = $(this).gmap('get','map').getZoom();   
            $.getJSON( 'http://skiweather.eu/gmap3/markers/index.php', {zoom: zoomLevel, 
                swLat: bounds.getSouthWest().lat(), swLon: bounds.getSouthWest().lng(), 
                neLat: bounds.getNorthEast().lat(), neLon: bounds.getNorthEast().lng()}, function(data) { 
                $.each( data.markers, function(i, marker) {
                    $('#map').gmap('addMarker', { 
                        'position': new google.maps.LatLng(marker.latitude, marker.longitude), 
                        'bounds': true 
                    }).click(function() {
                        $('#map').gmap('openInfoWindow', { 'content': marker.content }, this);
                    });
                });
            });
        });
    
    
        });
    </script>
    

    但是,它现在正在发送数据,但仍然无法正常工作,因为服务器不会给出任何响应(您确定有返回 JSON 数据的 web 服务吗?)

    【讨论】:

    • 返回的 JSON 无效,请使用您的控制台。
    • 重点应该放在奥地利
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多