【问题标题】:Gmap is not refreshing form second time onwardsGmap 不会从第二次开始刷新表格
【发布时间】:2013-01-21 13:42:55
【问题描述】:

我正在使用 Google gmap API 在我的 Phonegap 应用程序中显示 Google 地图。 gmap 工作正常。

但是,我的要求是根据用户选择更改标记,首先我要显示所有标记。从第二次开始,我需要根据用户的选择显示。我正在使用 Json 数据

下面是Gmap代码:

function showMap(data) {
    $('#map_canvas').gmap(
                        { 'center' : initialLocation,
                          'zoom' : 12,
                          'mapTypeControl' : false,
                          'navigationControl' : false,
                          'streetViewControl' : false
                        })
                        .bind('init', function(evt, map) {
                            if (data.Response.ShopListInfo instanceof Array) {
                                 $.each( data.Response.ShopListInfo, function(i, marker) {
                                              latitude = marker.Latitude;
                                              longitude = marker.Longitude; 
                                              displayMarkers(latitude, longitude, marker);
                                 });
                            }else{
                                latitude = data.Response.ShopListInfo.Latitude;
                                longitude = data.Response.ShopListInfo.Longitude; 
                                displayMarkers(latitude, longitude, data.Response.ShopListInfo);
                            }
                }); 
}

问题是从第二次调用开始“绑定”方法没有执行。

【问题讨论】:

    标签: jquery google-maps cordova jquery-mobile google-maps-markers


    【解决方案1】:

    我们只需要从第二次开始清除标记并单独调用 addMarkers 方法,如下所示。

    $('#map_canvas').gmap('clear', 'markers');
                    if (data.Response.ShopListInfo instanceof Array) {
                        $.each( data.Response.ShopListInfo, function(i, marker) {
                              latitude = marker.Latitude;
                                 longitude = marker.Longitude; 
                                 displayMarkers(latitude, longitude, marker);
                        });
                    }else{
                        latitude = data.Response.ShopListInfo.Latitude;
                        longitude = data.Response.ShopListInfo.Longitude; 
                        displayMarkers(latitude, longitude, data.Response.ShopListInfo);
                    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多