I'm trying to create a map with markers with Latitude and Longitude that comes from the database. With the Lat and Lng that is in the database i'm trying to pass it to a javascript file.
This code is from aspx.cs and gets the variables Lat and Lng. I created labels lblLat and lblLng just to see on the page if it gets the right data.
Here is the code from aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionCarpool"]);
DataRow dr = ExecuteDataSet(("SELECT Lat, Lng FROM Users Where UserID=1").ToString()).Tables[0].Rows[0];
Mapa prd = new Mapa();
prd.Lat = dr["Lat"].ToString();
prd.Lng = dr["Lng"].ToString();
lblLat.Text = prd.Lat;
lblLng.Text = prd.Lng;
conn.Close();
}
On my Javascript file, it makes the map appear but not the marker with the Lat and Lng. The part marker is where it should get the "Lat" and "Lng" thats on the file aspx.cs. The part "position: new google.maps.LatLng(41, -8)" works fine but on the part "position: new google.maps.LatLng("Lat", "Lng")" is where i want to get the data from the database on aspx.cs. On the aspx.cs file it gets the right data but now im just trying to find a way to pass that data to Lat and Lng thats on the Javascript file.
Here is my Javascript code:
function initialize() {
var latlng = new google.maps.LatLng(41.563059,-8.624268);
var myOptions = {
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: latlng
}
var map = new google.maps.Map(document.getElementById("map"), myOptions);
var marker = new google.maps.Marker({
//position: new google.maps.LatLng(41, -8),
position: new google.maps.LatLng("Lat", "Lng"),
map:map
});
}
Can anyone help my with this? I really apreciate it. Thanks!