Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 305681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:23:47+00:00 2026-05-12T07:23:47+00:00

I want to store a user’s current location on an ASP.NET MVC website for

  • 0

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 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?).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:23:48+00:00Added an answer on May 12, 2026 at 7:23 am

    In your second example, I don’t quite understand strAddress. Do you have the client’s address? Or is that their IP? I just tried that URL with my IP address and it says I’m about 1000 miles away.

    Anyways, I don’t see what’s wrong with #1. Just have something like this in your Site.Master:

    <script type="text/javascript">
      //other javascript here
      <% if (Sesssion.Contents["has_location"] == null) { %>
        $(document).ready(function_to_submit_location)
      <% } %>
    </script>
    

    edited to put the if statement in ASP tags — it’s not a javascript if.

    edit for those that want to use this code you’d have to put something in your controller in order to set session[“has_location”] = true when you get the location.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 245k
  • Answers 245k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer INDEX is one of MySQL's Reserved Words : Certain words… May 13, 2026 at 8:10 am
  • Editorial Team
    Editorial Team added an answer Separete api-bundle is probably the best choise. It allows you… May 13, 2026 at 8:10 am
  • Editorial Team
    Editorial Team added an answer You don't ever create the int that the pointer points… May 13, 2026 at 8:10 am

Related Questions

I want to store a user's current location on an ASP.NET MVC website for
I have a table. The table needs to store a number values about a
I have multiple asp.net sites. When a user logs unto one of the sites,
I have a web application that once signed in, personalizes almost all pages. I
If I am using asp.net's built-in membership provider, then how can I store arbitrary

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.