For the client side code, I have written the following:
<script>
function initialize(x, y) {
alert(x);
alert(y);
var mapProp = {
center: new google.maps.LatLng(x, y),
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?key=&sensor=false&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;
</script>
And for the server side code using asp.net:
protected void Button1_Click(object sender, EventArgs e) {
Page.ClientScript.RegisterStartupScript(this.GetType(), "calljs", "initialize(" + "45.508742" + ", " + "-0.120850" + ");", true);
}
However, when running this code, the values are sent to the function but the line below does not work:
center: new google.maps.LatLng(x, y)
It works when changing the line to this:
center: new google.maps.LatLng(51.4323,-0.12332)
How can I resolve this issue?