Click here to Skip to main content
15,906,625 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am showing a google map with geo coding in my usercontrol page.

The map is not displaying the address -

see the following code:

XML
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ChangeLocation.ascx.cs" Inherits="onlocal.UserControls.ChangeLocation" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<link href="../CSS/common.css" rel="stylesheet" type="text/css" />


 <script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAvpd8mjNgroIYlldQP4fM-hREifw3z0CLY54LRc8ZC14v-wuusRQrD9AaPPOw_rxAgdi_bPu9S-lQxg" type="text/javascript"></script>
    <script type="text/javascript">

    var map = null;
    var geocoder = null;
    function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
        geocoder = new GClientGeocoder();
      }
    }

    function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }
    alert('test link');
    initialize();
    alert('test link2');
    </script>

<cc1:ModalPopupExtender ID="ModalPopupChangeLocation" BehaviorID="ModalPopupChangeLocation"
    runat="server" BackgroundCssClass="modalBackground" TargetControlID="lnkDummy"
    PopupControlID="pnlModalPopupChangeLocation" CancelControlID="imgBtnCancel">
</cc1:ModalPopupExtender>
<asp:LinkButton ID="lnkDummy" runat="server"></asp:LinkButton>
<asp:Panel ID="pnlModalPopupchangelocation" runat="server" Style="display: none;">
<asp:UpdatePanel ID="updatechangelocation" runat="server">
        <ContentTemplate>
            <div style="width: 430px; height: 230px; overflow: hidden;" class="content" >
                <div class="blueNavPopUp" style="width: 430px;">
                    <div class="blueNavTextPopUp">
                        <asp:Label ID="lblTitle" runat="server" class="whiteTabText">Change
            Location</asp:Label></b></div>
                    <div class="collaspebtmPopUp">
                        <asp:ImageButton ID="imgBtnCancel" runat="server" ImageUrl="~/images/CloesImg.gif" OnClientClick="javascript:$find('ModalPopupChangeLocation').hide(); return false;"
                            alt="" /></div>
                </div>
            <p>
        <input type="text" size="60" name="address" value="1600 Amphitheatre Pky, Mountain View, CA" />
        <input type="submit" value="Go!" onclick="initialize(); return false;" />
      </p>
      <div id="map_canvas" style="width: 500px; height: 300px; background-color:Aqua;"></div>
</div>
        </ContentTemplate>
    </asp:UpdatePanel>
&nbsp;</asp:Panel><p>
    </p>
Posted
Updated 2-Sep-10 4:44am
v2
Comments
Dalek Dave 2-Sep-10 10:45am    
Minor Edit for Grammar.

In your submit button, you are calling initialize(); Shouldn't you be calling showAddress();
 
Share this answer
 
v2
Comments
balongi 2-Sep-10 7:05am    
i'll tryed but its not working............
Dylan Morley 2-Sep-10 7:11am    
OK, I'll bite - please elaborate. What happens? Have you debugged the code, is it running OK or throwing an exception?

Are you debugging in IE or Firefox?

'Not working' doesn't really help anyone here - you must give specific examples of where it's going wrong! Error messages etc..
balongi 2-Sep-10 7:49am    
me running it on firefox...the map is not displayed after made changes by me



after clicking go button doesn't happen anything... onclick="showaddress(this.address.value)",returnfalse;"/>





Dylan Morley 2-Sep-10 7:52am    
OK, so do some debugging...

* Open Firebug
* In the showAddress() function, add a breakpoint to the first line of code - if (geocoder) {
* Run the code, the debugger halts at you breakpoint

What is the state of the geocoder variable? Is it valid? Step to the next line of code, is it going to geocoder.getLatLng or is the function moving to exit straight away

You can work this out if you debug a bit
balongi 2-Sep-10 7:56am    
can usercontrol.ascs have features of breakpint
The 'this' keyword within the context you are using will refer to the document I think? Again, in Firebug you can determine this

Basically, this.address doesn't exist. You haven't given the object an ID, only a name. When you use use ASP.Net controls, I'm sure .Net mangles all the IDs anyway...e.g

'myControl_1_address'

you should still give your element an ID anyway, e.g

<input type="text" size="60" id="address" name="address" value="1600 Amphitheatre Pky, Mountain View, CA" />

You can try

https://developer.mozilla.org/en/document.getElementsByName[^]

e.g
var address = document.getElementsByName('address');

That's the last help I'm giving you on this! Between using Firebug effectively and finding your element on the page, you will be able to figure this out if you try
 
Share this answer
 
Comments
balongi 2-Sep-10 10:06am    
Thanx for being kind... ;)

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