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
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
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>");
}