I want to store a user's current location on an ASP.NET MVC website for the duration of a session. Because I want to use the location server-side, the way I think this should work (maybe other suggestions?) is that when a user first hits the website, I get the location and store it in the session, so on later requests it does not have to be looked up again.
The best way I can find is to use Google's ClientLocation method:
<script src="http://www.google.com/jsapi?key=YOURAPIKEY" type="text/javascript"></script>
<script>
google.load("jquery", "1.2.6");
google.load("jqueryui", "1.5.2");
var yourLocation = google.loader.ClientLocation.address.city + ", "
+ google.loader.ClientLocation.address.region;
</script>
My question is how best to get the location looked up in this Javascript code back to the server to store in the database or in the session. I know that I could call a controller action using jQuery to pass the location:
$.post("/Home/StoreLocation", location, function(){});
But for performance I don't want this to be happening on every single page load. The other way i thought to do it was to call Google's apis from .NET code by doing something like this (a call to geocoding):
string path = "http://maps.google.com/maps/geo?q=" + strAddress + "&output=csv&key=" + apiKey;
WebClient client = new WebClient();
string[] eResult = client.DownloadString(sPath).ToString().Split(',');
//Parse the array
But I can't find any equivalent way to call ClientLocation directly from a URL like this - all the examples I have seen use google.loader (which I don't think I can use when doing it this way?) Another thing I have considered is using Google's .NET library, but I can't find anything in there to do a location lookup (maybe I am wrong?).
Any suggestions greatly appreciated - I feel I am over-thinking this and missing something obvious!