Click here to Skip to main content
15,878,970 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i find this code it get me location but i don't know how to save client location in sql database to retrieval it Later

C#
<html>
<head>
<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;
            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>
</head>
<body>
<div id="mapContainer"></div>
</body>
</html>
Posted
Comments
bbirajdar 29-Mar-13 7:54am    
What have you tried?
hany1002 29-Mar-13 8:10am    
i would like to save location show the map in sql database
bbirajdar 29-Mar-13 8:18am    
I would like to have a cheeze pizza and coke for dinner today... But the question was - What have you tried (other than copy pasting the above code from code.google.com) ?
[no name] 29-Mar-13 8:38am    
5+ for that one.
bbirajdar 29-Mar-13 9:27am    
:)

1 solution



if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var latitude = position.coords.latitude;
var longitude = position.coords.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!"
});
document.getElementById("longitude").value=longitude;
document.getElementById("latitude").value=latitude;

});
} else {
alert("Geolocation API is not supported in your browser.");
}


#mapContainer {
height: 500px;
width: 800px;
border:10px solid #eaeaea;
}










Now Save The Value Of These Two Hidden Tagas.
 
Share this answer
 
Comments
bbirajdar 29-Mar-13 10:29am    
Nice answer.. But the OP needs to save it in the database.. I dont see the values being saved in the database...

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