Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In the OnClientClick of Button in my ASP.Net Application, I call this function to show a JQueryUI dialog with Google Map Inside. Everything works well for the first time. But, Second time, the map seems to be blank with gray background, But, every other controls inside map are shown. This is my code. Is there any method to dispose the map on close, so that I can reload map again on next button click.

XML
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
function loadMap()
{

       var currentMapPosition = new google.maps.LatLng($('#<%=txLatitude.ClientID %>').val(), $('#<%= txLongitude.ClientID %>').val());
       var mapOptions = {
            center: currentMapPosition,
            zoom: 14,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var infoWindow = new google.maps.InfoWindow();
        var latlngbounds = new google.maps.LatLngBounds();
        var map = new google.maps.Map(document.getElementById("gmap-dialog"), mapOptions);

        var marker = new google.maps.Marker({
            position: currentMapPosition,
            map: map,
            title: 'SubProject Location'
        });
       //collects New Location, and closing dialog on click
        google.maps.event.addListener(map, 'click', function (e) {
            var latitude = e.latLng.lat();
            var longitude = e.latLng.lng();

                  var marker = new google.maps.Marker({
                    position: e.latLng,
                    map: map,
                    title: 'SubProject Location'
                });
                // Center of map
                map.panTo(new google.maps.LatLng(latitude,longitude));
                $('#<%= txLatitude.ClientID %>').val(e.latLng.lat() ) ;
                $('#<%= txLongitude.ClientID %>').val(e.latLng.lng() ) ;

               $("#gmap-dialog").dialog('close');
        });

          $("#gmap-dialog").dialog('open');
}
</script>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900