You need to do it this way.
1. Populate a List of addresses from database (I have created in code) and then assign to a hidden field.
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
List<string> addresses = new List<string>();
addresses.Add("Mumbai");
addresses.Add("Pune");
addresses.Add("Delhi");
addresses.Add("Hyderabad");
addresses.Add("Chennai");
hfAddresses.Value = string.Join(",", addresses);
}
}
2. Now using this Hidden Field value, create an Array in JavaScript and ussing Geocoding API get Latitude and Longitude and plot markers on Map.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
window.onload = function () {
var addresses = document.getElementById("<%=hfAddresses.ClientID %>").value.split(',');
var mumbai = new google.maps.LatLng(18.9750, 72.8258);
var mapOptions = {
center: mumbai,
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
var latlngbounds = new google.maps.LatLngBounds();
var markers = new Array();
for (i = 0; i < addresses.length; i++) {
var address = addresses[i];
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var Latlng = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());
var marker = new google.maps.Marker({
position: Latlng,
map: map,
title: results[0].formatted_address
});
markers.push(marker);
latlngbounds.extend(marker.position);
google.maps.event.addListener(marker, "click", function (e) {
infoWindow.setContent(marker.title);
infoWindow.open(map, marker);
});
if (markers.length == addresses.length) {
map.setCenter(latlngbounds.getCenter());
map.fitBounds(latlngbounds);
}
} else {
alert("Request failed.")
}
});
}
}
</script>
<div id="dvMap" style="width: 500px; height: 500px">
</div>
<asp:HiddenField ID="hfAddresses" runat="server" />
</form>
</body>
</html>