Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Location
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
 
<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 29-Mar-13 2:46am
Comments
aspnet_regiis -i at 29-Mar-13 7:54am
   
What have you tried?
hany1002 at 29-Mar-13 8:10am
   
i would like to save location show the map in sql database
aspnet_regiis -i at 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) ?
ThePhantomUpvoter at 29-Mar-13 8:38am
   
5+ for that one.
aspnet_regiis -i at 29-Mar-13 9:27am
   
:)
mr.priyank at 29-Mar-13 10:07am
   
Plz dont make fun of anyones question. Just try to see what he is trying to ask.
aspnet_regiis -i at 29-Mar-13 10:25am
   
No body is trying to make fun.. Do you think we are paid to help him ?? You and your friend need to read these links What have you tried ? ^ and Rules for posting questions on code project ^
ryanb31 at 29-Mar-13 8:14am
   
You'll have to write code to save it to the database. Where are you stuck?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

<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!"
});
document.getElementById("longitude").value=longitude;
document.getElementById("latitude").value=latitude;

});
} else {
alert("Geolocation API is not supported in your browser.");
}
</script>
 
#mapContainer {
height: 500px;
width: 800px;
border:10px solid #eaeaea;
}
 
</head>
<body>
<input type="hidden" id="latitude" name="latitude" />
<input type="hidden" id="longitude" name="longitude" />

 
</body>
</html>
 
Now Save The Value Of These Two Hidden Tagas.
  Permalink  
Comments
aspnet_regiis -i at 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)

  Print Answers RSS
0 OriginalGriff 190
1 Jochen Arndt 165
2 PIEBALDconsult 150
3 BillWoodruff 148
4 DamithSL 140
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 29 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100