Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i retrieve map for location after save


latitude , longitude in the database


This code using to save location

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <script src="http://maps.google.com/maps/api/js?sensor=false">
    </script>
    <script type="text/javascript">
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function (position) {
                var latitude = position.coords.latitude;
                var longitude = position.coords.longitude;
                document.getElementById("<%=hfLat.ClientID %>").value = latitude;
                document.getElementById("<%=hfLon.ClientID %>").value = longitude;
                var coords = new google.maps.LatLng(latitude, longitude);
                var mapOptions = {
                    zoom: 15,
                    center: coords,
                    mapTypeControl: true,
                    navigationControlOptions: {
                        style: google.maps.NavigationControlStyle.SMALL
                    },
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                map = new google.maps.Map(
                document.getElementById("mapContainer"), mapOptions
                );
                var marker = new google.maps.Marker({
                    position: coords,
                    map: map,
                    title: "Your current location!"
                });
 
            });
        } else {
            alert("Geolocation API is not supported in your browser.");
        }
    </script>
    <style type="text/css">
        #mapContainer
        {
            height: 500px;
            width: 800px;
            border: 10px solid #eaeaea;
        }
    </style>
    <div id="mapContainer">
    </div>
    <asp:HiddenField ID="hfLat" runat="server" />
    <asp:HiddenField ID="hfLon" runat="server" />
    <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
    </form>
</body>
</html>




C#
protected void btnSave_Click(object sender, EventArgs e)
{
    string latitude = hfLat.Value;
    string longitude = hfLon.Value;
 
    //Save to database here
}
Posted

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