Multiple Markers for Google Maps API V3 With Literal Asp.Net Control-Collection of common programming errors
I am using the following code to add Marker in Google Maps (API V3) , I use XML file for store locations
protected void Page_Load(object sender, EventArgs e)
{
string locations = "";
string lastlat = "", lastlng = "";
XDocument xmlDoc = XDocument.Load(Server.MapPath("~/App_Data/Map.xml"));
var query = from st in xmlDoc.Descendants("Position")
select st;
foreach (var p in query)
{
lastlat = p.Element("Latitude").Value;
lastlng = p.Element("Longitude").Value;
locations += "var marker = new google.maps.Marker({position: new google.maps.LatLng("
+ p.Element("Latitude").Value + ","
+ p.Element("Longitude").Value + "),info:\""
+ p.Element("Name").Value + "\",title:\""
+ p.Element("Name").Value + "\",map: map});marker.setMap(map)";
}
Label1.Text = locations;
js.Text = @"function initialize() { var myLatlng = new google.maps.LatLng(" + lastlat + "," + lastlng + "); var myOptions = {zoom: 16, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById('map'), myOptions);" + locations + "marker.setMap(map);}";
}
and this code
but do not show map in webpage!!!
This gives two error
Uncaught SyntaxError: Unexpected token var
Uncaught ReferenceError: initialize is not defined