Click here to Skip to main content
15,885,146 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello
I have a problem with displaying maps
in page load the map is displayed, but when I want to execute the code on a button click the map is not displayed

function javascript to display Map

JavaScript
 function AfficherMap() {
//     alert("ssss");
        var mapOptions = {
            center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
            zoom: 10,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
        var infoWindow = new google.maps.InfoWindow();
        var lat_lng = new Array();
        var latlngbounds = new google.maps.LatLngBounds();
        for (i = 0; i < markers.length; i++) {
            var data = markers[i]
            var myLatlng = new google.maps.LatLng(data.lat, data.lng);
            lat_lng.push(myLatlng);
           
            var marker = new google.maps.Marker({
                position: myLatlng,
                map: map,
                title: data.title
            });
            latlngbounds.extend(marker.position);
            (function (marker, data) {
                google.maps.event.addListener(marker, "click", function (e) {
                    infoWindow.setContent(data.description);
                    infoWindow.open(map, marker);
                });
            })(marker, data);
        }
        map.setCenter(latlngbounds.getCenter());
        map.fitBounds(latlngbounds);
        /////////////////////////////////////////77777

        var service = new google.maps.DirectionsService();
        var directionsDisplay = new google.maps.DirectionsRenderer();    
        directionsDisplay.setMap(map);

var waypts = [];
for(j=1;j<lat_lng.length-1;j++){            
      waypts.push({location: lat_lng[j],
                   stopover: true});
}

var request = {
    origin: lat_lng[0],
    destination: lat_lng[lat_lng.length-1],
    waypoints: waypts,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
  };
        service.route(request,function(result, status) {                
            if(status == google.maps.DirectionsStatus.OK) {                 
                  directionsDisplay.setDirections(result);
            } else { alert("Directions request failed:" +status); }
        });
    }


Button Click

C#
protected void Button3_Click(object sender, EventArgs e)
      {

          string s = "2014-11-05";
          LocalisationVenteDao.ds.Reset();
          LocalisationVenteDao.Instance.LocalisationVenteToDB(Sql.Instance.GetSqlConnection(),s);
          rptMarkers.DataSource = LocalisationVenteDao.ds.Tables[0];
          GridView1.DataSource = LocalisationVenteDao.ds.Tables[0];
          rptMarkers.DataBind();
          GridView1.DataBind();
          ClientScript.RegisterStartupScript(this.GetType(), "blablaosef", "<script type='text/javascript'>AfficherMap();</script>");


      }
Posted
Comments
Afzaal Ahmad Zeeshan 13-Nov-14 5:22am    
Have you tried writing this code without that script element tag?

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