0

我使用Google gmap API在我的Phonegap應用程序中顯示Google地圖。 gmap工作正常。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); 
          } 
       }); 
} 

的問題是從起「綁定」方法不執行第二個呼叫。

回答

0

我們只需要從第二次開始清除標記,並單獨調用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); 
       } 
相關問題