Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to pass values from a Javascript to ASP.Net Texbox.

    Hi All,

    I am trying to get GeoCodes from Google Maps ussing google map Javascript API.
    I am able to get the same. But do not know how to pass it on to ASP.Net Textbox with name "txtLatLng".

    Below is the code. Requesting you to guide me on the same.

    Code:
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script language="javascript" type="text/javascript">
    
        var map;
        var geocoder;
        function InitializeMap() {
    
            var latlng = new google.maps.LatLng(-34.397, 150.644);
            var myOptions =
            {
                zoom: 8,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                disableDefaultUI: true
            };
            map = new google.maps.Map(document.getElementById("map"), myOptions);
        }
    
        function FindLocaiton() {
            geocoder = new google.maps.Geocoder();
            InitializeMap();
    
           
            
            var address = document.getElementById('<%= txtAddressInput.ClientID %>').value;
            //var LatLngCode = document.getElementById("<%:txtLatLng.ClientID %>").value;
         
            geocoder.geocode({ 'address': address }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    map.setCenter(results[0].geometry.location);
                    var marker = new google.maps.Marker({
                        map: map,
                        position: results[0].geometry.location
    
                    });
    
                    var infowindow = new google.maps.InfoWindow({
                        content: 'Location info: <br/>Country Name:<br/>LatLng: ' + results[0].geometry.location                    
                    });
                    google.maps.event.addListener(marker, 'click', function () {
                        // Calling the open method of the infoWindow 
                        infowindow.open(map, marker);
                    });
                }
                else {
                    alert("Geocode was not successful for the following reason: " + status);
                }
            });
    
        }
    
    
        
          function btnGeoCode_onclick() {
              //alert("Script Not Yet Developed");
              FindLocaiton();
    
          }
    
          
    
    
    
          window.onload = InitializeMap;
            
        </script>
    Requesting guidance.
    Sudhir

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Same way you got the address. only in reverse:
    Code:
    document.getElementById("<%= txtLatLng.ClientID %>").value
         = results[0].geometry.location.toString();
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •