Click here to Skip to main content
15,900,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all,
i have written the following code. it does not seem to have any error as it is getting compiled. but the map is not getting displayed. pl help

JavaScript
<head runat="server">

        <title>Google Maps JavaScript API Example</title>
    
        <script src="http://maps.google.com/maps?file=api&v=2&key=abcdefg"
      type="text/javascript">
        </script>
    
        <script type="text/javascript">
    
        function disp() 
        {
            var lat = document.getElementById('<%= txtlat.ClientID %>').value;
            var lng = document.getElementById('<%= txtlng.ClientID %>').value;
            load(lat, lng)
            alert('inside disp()');
        }
    
        function load(float a, float b) 
        {
            if (GBrowserIsCompatible()) 
            {
                var map = new GMap2(document.getElementById("map"));
                map.setCenter(new GLatLng(a, b), 15);
                var marker = new GMarker(new GLatLng(a, b));
	            map.addOverlay(marker);
            }
        }
    
        </script>

    </head>

    <body>

        <div id="map" style="width: 500px; height: 300px"></div>

            <form id="form1" runat="server">
    
                <div>
                    <br />
                    <asp:Label ID="lbllat" runat="server" Text="Enter the latitude:" Width="130px"> 
                    <asp:TextBox ID="txtlat" runat="server"><br />
                    <br />
                    <asp:Label ID="lbllng" runat="server" Text="Enter the longitude:" ToolTip=" " Width="130px"> 
                    <asp:TextBox ID="txtlng" runat="server">
                    <br />
                    <br />
                                           
                      
                    <asp:Button ID="btnsubmit" runat="server" Text="Submit" onclientclick="disp"/>
                </div>
      
            </form>
    
    </body>
Posted

The line in your script :
JavaScript
http://maps.google.com/maps?file=api&v=2&key=abcdefg


is giving the following error :
function GBrowserIsCompatible() {return false;}alert("This web site needs a different Google Maps API key. A new key can be generated at http://code.google.com/apis/maps/signup.html.");function GUnload() {}var G_API_VERSION;
 
Share this answer
 
Comments
debo_india 7-Oct-11 1:06am    
ok thanks a lot! i am trying to get a new key and run it again!
debo_india 7-Oct-11 1:15am    
hi, i used the following key but still its not getting displayed :(

<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA3VhlbU84rXxxNJIwhgnCZBSuP9ZqWvsczlCo05gzZUKk3SVL5BQDjOk8Uo9hfXvOcey1b2DBrQ_rUA" type="text/javascript">
</script>
Mehdi Gholam 7-Oct-11 1:29am    
Try vivek's code
Mehdi Gholam 7-Oct-11 1:29am    
Your key seems fine, and google is returning information.
debo_india 7-Oct-11 3:55am    
ok will try it..thanks for the reply
I suggest refer to the following article, very nicely explained.
Google Maps in HTML, ASP.NET, PHP, JSP etc. with ease[^]

Looking at your code, debugging would help. Some hints would be
1. Check what GBrowserIsCompatible is returning

Also
1. most of your tags doesnot have closing tags.
2. check for error in java script
3. onclientclick="disp();"

fixing all the errors on the page should get it running.

following altered code changes map on my machine.

XML
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">

        <title>Google Maps JavaScript API Example</title>

        <script src="http://maps.google.com/maps?file=api&v=2&key=abcdefg"
      type="text/javascript">
        </script>

        <script type="text/javascript">

        function disp()
        {
            var lat = document.getElementById('<%= txtlat.ClientID %>').value;
            var lng = document.getElementById('<%= txtlng.ClientID %>').value;
            load(lat, lng);
            alert('inside disp()');
        }

        function load(a, b)
        {
            alert('inside load');

            if (GBrowserIsCompatible())
            {
                var map = new GMap2(document.getElementById("map"));
                map.setCenter(new GLatLng(a, b), 15);
                var marker = new GMarker(new GLatLng(a, b));
                map.addOverlay(marker);
            }
        }

        </script>

    </head>

    <body>

        <div id="map" style="width: 500px; height: 300px"></div>

            <form id="form1" runat="server">

                <div>
                    <br />
                    <asp:Label ID="lbllat" runat="server" Text="Enter the latitude:" Width="130px"/>
                    <asp:TextBox ID="txtlat" runat="server"/><br />
                    <br />
                    <asp:Label ID="lbllng" runat="server" Text="Enter the longitude:" ToolTip=" " Width="130px"/>
                    <asp:TextBox ID="txtlng" runat="server"/>
                    <br />
                    <br />


                    <asp:Button ID="btnsubmit" runat="server" Text="Submit" onclientclick="disp();"/>
                </div>

            </form>

    </body>

    </html>
 
Share this answer
 
v3
Comments
debo_india 7-Oct-11 3:54am    
ok thanks vivek..will try it and reply
debo_india 7-Oct-11 3:59am    
no vivek, its getting displayed for 1 sec & then disappearing..just like before
hi all,
i got the solution..when i took the button object as an input button (and not as an asp button ), i got the correct result. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900