Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi
i have this scripts for maps and i want to take the value of latude and longitued in code behind so can i get it?
JavaScript
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC6v5-2uaq_wusHDktM9ILcqIrlPtnZgEk&sensor=false">
</script>

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places">
</script>

<script type="text/javascript">
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(success);
    } else {
        alert("Geo Location is not supported on your current browser!");
    }
    function success(position) {
        var lat = position.coords.latitude;
        var long = position.coords.longitude;
        var city = position.coords.locality;
        var myLatlng = new google.maps.LatLng(lat, long);
        var myOptions = {
            center: myLatlng,
            zoom: 12,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        var marker = new google.maps.Marker({
            position: myLatlng,
            title: "lat: " + lat + " long: " + long
        });

        marker.setMap(map);
        var infowindow = new google.maps.InfoWindow({ content: "<font color="black">User Address<br /> Latitude:" + lat + "<br /> Longitude:" + long + "" });
        infowindow.open(map, marker);
    }
</script></font>
Posted
Updated 1-Jan-14 21:43pm
v2

Let see an example to pass a value from javascript from one page to another page:
1. In the first aspx page, say Page1.aspx, add:
XML
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button1" runat="server"  OnClientClick="passValue2CodeBehind();" Text="Button" onclick="Button1_Click" />

2. In the code behind of the first aspx page, register a javascript in the Page_Load event:
ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script language='javascript'>function passValue2CodeBehind() {  var lat='1.2345'; document.getElementById('HiddenField1').value = lat; }  </script>");

3. Add this line to the Button1_Click in the code behind:
Response.Redirect("~/Page2.aspx?lat=" + HiddenField1.Value);


4. Create the Page2.aspx and add a label:
<asp:Label ID="Label1" runat="server"></asp:Label>

5. In the Page_Load event of the code behind of Page2.aspx, add this:
Label1.Text = this.Request.QueryString["lat"];

Now, launch Page1.aspx to see the working.
 
Share this answer
 
v2
Comments
TrushnaK 2-Jan-14 6:04am    
detail answer... nice
Peter Leow 2-Jan-14 6:37am    
Thank you.
Easiest way would be to set the longitude and latitude values in HiddenFields through javascript and then retrieve it through Codebehind code.
 
Share this answer
 
v2
i solve it but with dynamic data
this script document.getElementById('HiddenField1').value = lat;
can not get the inter data it give string to find inter data i find another solution
 
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