Jquery Gmap不会从第二次开始刷新
我正在使用GoogleGMAPAPI在我的Phonegap应用程序中显示Google地图。gmap运行良好 但是,我的要求是根据用户选择更改标记,首先我显示所有标记。从第二次开始,我需要显示为用户选择。我使用的是Json数据 以下是Gmap代码:Jquery Gmap不会从第二次开始刷新,jquery,google-maps,cordova,jquery-mobile,google-maps-markers,Jquery,Google Maps,Cordova,Jquery Mobile,Google Maps Markers,我正在使用GoogleGMAPAPI在我的Phonegap应用程序中显示Google地图。gmap运行良好 但是,我的要求是根据用户选择更改标记,首先我显示所有标记。从第二次开始,我需要显示为用户选择。我使用的是Json数据 以下是Gmap代码: function showMap(data) { $('#map_canvas').gmap( { 'center' : initialLocation,
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);
}
});
}
问题是从第二次调用开始,“bind”方法就没有执行。我们只需要从第二次调用开始清除标记,然后单独调用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);
}