【问题标题】:Google Map V3: Loading Markers using AJAX+ASP/PHP and Reload on Ruquest or EventGoogle Map V3:使用 AJAX+ASP/PHP 加载标记并在 Ruquest 或事件上重新加载
【发布时间】:2011-10-07 22:59:21
【问题描述】:

您好,我搜索了很多东西,找到了很多内容,但没有找到我真正需要的内容。

我可以加载所有标记但无法刷新或重新加载它请帮我看看这里的代码:

    $(document).ready(function() {

    var myLatLng = new google.maps.LatLng(24.86802, 67.06416);
  MYMAP.init('#map', myLatLng, 11);

  $(document).ready(function(e){
        MYMAP.placeMarkers('testasp.asp');

  });
});


var curr_infw;
var MYMAP = {
    map: null,
    bounds: null,
    infowindow:null
}

MYMAP.init = function(selector, latLng, zoom) {
  var myOptions = {
    zoom:zoom,
    center: latLng,
    mapTypeId: google.maps.MapTypeId.HYBRID
  }
  this.map = new google.maps.Map($(selector)[0], myOptions);
    this.bounds = new google.maps.LatLngBounds();
}

MYMAP.placeMarkers = function(filename) {
    $.get(filename, function(xml){
        $(xml).find("marker").each(function(){
            var name = $(this).find('name').text();
            var address = $(this).find('address').text();

            // create a new LatLng point for the marker
            var lat = $(this).find('lat').text();
            var lng = $(this).find('lng').text();
            var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
            var infowindow = null;

            // extend the bounds to include the new point
            MYMAP.bounds.extend(point);

            var marker = new google.maps.Marker({
                position: point,
                map: MYMAP.map,
                clickable: true,
                icon: 'truck_green.png'

            });

            //var infowindow = null;
            infoWindow = new google.maps.InfoWindow();
            var html='<strong>'+name+'</strong.><br />'+address;
            google.maps.event.addListener(marker, 'mouseover', function() {
                infoWindow.setContent(html);
                infoWindow.open(MYMAP.map, marker);





            });
            MYMAP.map.fitBounds(MYMAP.bounds);
        });
    });
}

如果有人帮助我,我想使用点击事件或 settimeout 函数刷新它。

问候并期待很快在这里听到。谢谢

【问题讨论】:

    标签: ajax google-maps-api-3


    【解决方案1】:

    不是答案,但这是什么意思?

        $(document).ready(function() {
    
        var myLatLng = new google.maps.LatLng(24.86802, 67.06416);
      MYMAP.init('#map', myLatLng, 11);
    
      $(document).ready(function(e){
            MYMAP.placeMarkers('testasp.asp');
    
      });
    });
    

    为什么要嵌套 document.ready?做吧

    $(document).ready(function() {
        var myLatLng = new google.maps.LatLng(24.86802, 67.06416);
        MYMAP.init('#map', myLatLng, 11);
        MYMAP.placeMarkers('testasp.asp');
    });
    

    【讨论】:

    • 我要做的是先初始化地图,然后再初始化标记,但根据您的更正,您认为它会重新加载或刷新来自 MYMAP.placeMarkers('testasp.asp') 的标记; ??????
    【解决方案2】:

    活动用

    google.maps.event.addListener([ mapObject ], 'bounds_changed', function() {
        // [ update code here ]
    });
    

    【讨论】:

      猜你喜欢
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 2015-04-04
      • 1970-01-01
      • 1970-01-01
      • 2013-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多