C Sharper
C Sharper

Reputation: 8646

Not getting gmap in asp.net

I have made gmap user control as follows:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="gmap.ascx.vb" Inherits="gmap" %>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDgj_OLNlWvNs8nr2JPLON4GPCgsxTJRnU&sensor=false">
</script>

<script type="text/javascript">
function initialize(lat,lang)
{
var mapProp = {
center: new google.maps.LatLng(lat, lang),
  zoom:5,
  mapTypeId:google.maps.MapTypeId.ROADMAP
  };
var map=new google.maps.Map(document.getElementById("googleMap")
  ,mapProp);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>

<body>
<div id="googleMap" style="width:500px;height:380px;"></div>



</body>
</html>

I pass the lattitude and longitude from backend function as:

 Public Sub LattitudeLongitude(ByVal lat As Decimal, ByVal longit As Decimal)
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "MyScript", "javascript:initialize('" & lat & "','" & longit & "')", True)
    End Sub

Its not showing me location.

I debugged program, its getting values of lattitude and longitude everywhere.

Its showing me as follows:

enter image description here

I dont know, why its not showing me location. Please help me.

Upvotes: 0

Views: 1400

Answers (1)

Zaki
Zaki

Reputation: 5600

The initialize() function runs on every page load. and you are calling it on a button click. So when testing if you do this the first time you click the button it will pass the latitude and longitude and on post-back it will be empty, hence giving you blank map.

All you need to do is to change the function name in scrip and code behind :

function DisplayMap(lat, lang) {

and code behind:

Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "javascript:DisplayMap('" + lat + "','" + longit + "')", true);

and remove google.maps.event.addDomListener(window, 'load', initialize);

Upvotes: 1

Related Questions