Their examples are quite nice so I went ahead to use this new control. I put the GooglePoint inside a reader so I can try to set multiple points on the map. I'm only getting the last one. I think it has something to do with the errors I get. They are as
follows:
1. I click ignore to get past this error: Microsoft JScript runtime error: Unable to get value of the Property 'PageRequestManager': object is null or undefined
2. When I click anywhere on the map, this event fires: Microsoft JScript runtime error: '__doPostBack' is undefined
My code reads like this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GoogleMapForASPNet1.GoogleMapObject.APIKey = ConfigurationManager.AppSettings["GoogleAPIKey"];
GoogleMapForASPNet1.GoogleMapObject.Width = "600px"; // You can also specify percentage(e.g. 80%) here
GoogleMapForASPNet1.GoogleMapObject.Height = "600px";
GoogleMapForASPNet1.GoogleMapObject.ZoomLevel = 3;
GoogleMapForASPNet1.GoogleMapObject.CenterPoint = new GooglePoint("1", 43.66619, -79.44268);
string _csVHG = ConfigurationManager.AppSettings["SiteSqlServer"];
SqlConnection conn = new SqlConnection(_csVHG);
GooglePoint gp = new GooglePoint();
try
{
string query = "Select PropertyID, Latitude, Longitude, ShortDescr, Description, PropertyImage from WEPropertyT";
SqlCommand cmd = new SqlCommand(query, conn);
conn.Open();
SqlDataReader rd = cmd.ExecuteReader();
int i = 0;
while (rd.Read())
{
gp.ID = i.ToString();
gp.Latitude = Convert.ToDouble(rd.GetValue(1));
gp.Longitude = Convert.ToDouble(rd.GetValue(2));
gp.InfoHTML = "Hello there!";
GoogleMapForASPNet1.GoogleMapObject.Points.Add(gp);
i++;
}
conn.Close();
}
catch (Exception ex)
{
}
}
}
As you can see, the code should work since my reader steps through correctly one record at a time building a list of points. However instead of getting 4 points (i have 4 records in my test) I get the very last one. Can someone shed some light on what is
going on here?
bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Google Maps Control for ASP.NET
Jan 25, 2012 12:17 PM|LINK
I downloaded a project from Code Project regarding a Google Map control for ASP.NET from here: http://www.codeproject.com/Articles/24468/Google-Maps-Control-for-ASP-NET-Part-1
Their examples are quite nice so I went ahead to use this new control. I put the GooglePoint inside a reader so I can try to set multiple points on the map. I'm only getting the last one. I think it has something to do with the errors I get. They are as follows:
1. I click ignore to get past this error: Microsoft JScript runtime error: Unable to get value of the Property 'PageRequestManager': object is null or undefined
2. When I click anywhere on the map, this event fires: Microsoft JScript runtime error: '__doPostBack' is undefined
My code reads like this:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GoogleMapForASPNet1.GoogleMapObject.APIKey = ConfigurationManager.AppSettings["GoogleAPIKey"]; GoogleMapForASPNet1.GoogleMapObject.Width = "600px"; // You can also specify percentage(e.g. 80%) here GoogleMapForASPNet1.GoogleMapObject.Height = "600px"; GoogleMapForASPNet1.GoogleMapObject.ZoomLevel = 3; GoogleMapForASPNet1.GoogleMapObject.CenterPoint = new GooglePoint("1", 43.66619, -79.44268); string _csVHG = ConfigurationManager.AppSettings["SiteSqlServer"]; SqlConnection conn = new SqlConnection(_csVHG); GooglePoint gp = new GooglePoint(); try { string query = "Select PropertyID, Latitude, Longitude, ShortDescr, Description, PropertyImage from WEPropertyT"; SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); SqlDataReader rd = cmd.ExecuteReader(); int i = 0; while (rd.Read()) { gp.ID = i.ToString(); gp.Latitude = Convert.ToDouble(rd.GetValue(1)); gp.Longitude = Convert.ToDouble(rd.GetValue(2)); gp.InfoHTML = "Hello there!"; GoogleMapForASPNet1.GoogleMapObject.Points.Add(gp); i++; } conn.Close(); } catch (Exception ex) { } } }As you can see, the code should work since my reader steps through correctly one record at a time building a list of points. However instead of getting 4 points (i have 4 records in my test) I get the very last one. Can someone shed some light on what is going on here?
bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: Google Maps Control for ASP.NET
Jan 25, 2012 12:40 PM|LINK
Ok, figured this out on my own. I remembered that the GooglePoint gp = new GooglePoint(); has to be inside the reader loop.