Here's my newbie question, hope the formatting is correct :)
I'm working on an ASP.NET, C# application
that retrieves coordinates (Lat, Lon) from SQL and displays them as markers (which is working fine). However, when I try to add infowindow() to those markers, the map is not displaying properly.
I want each marker to have its own infowindow() displayed.
This is the code in my CS page:
protected void Page_Load(object sender, EventArgs e)
{
string markers = GetMarkers();
Literal1.Text = @"<script type='text/javascript'>
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(41.43242, -89.209343),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var image = new google.maps.MarkerImage('pic/marker.png', null, null, null, new google.maps.Size(30, 42));
var myMap = new google.maps.Map(document.getElementById('mapArea'),
mapOptions);" + markers + @"}
</script>";
}
protected string GetMarkers()
{
string markers = "";
using (SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=web1;Integrated Security=True"))
{
SqlCommand cmd = new SqlCommand("SELECT Lat, Lan FROM Location", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
int i = 0;
while (reader.Read())
{
i++;
markers +=
@"var marker" + i.ToString() + @" = new google.maps.Marker({ icon: image,
position: new google.maps.LatLng(" + reader["Lat"].ToString() + ", " +
reader["Lan"].ToString() + ")," +@"map: myMap});";
}
}
return markers;
}