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

  • SEARCH
  • Home
  • 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 6079549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:57:33+00:00 2026-05-23T10:57:33+00:00

I have a JavaScript map that takes some coordinates from a django view/function when

  • 0

I have a JavaScript map that takes some coordinates from a django view/function when the template page first loads up like this:

<script type="text/javascript">    
...
map.setCenter(new f.LatLng{{lat_long}}, 11);
...
</script>

I also have another function on the same views.py file handling an ajax request that does some calculations and returns new coordinates that supposed to update the same spot where {{lat_long}} tag is.

So in a way I should make the {{lat_long}} coming from the function when the page first loads up disappear and replace it with a new {{lat_long}} that’s coming form the function handling the ajax request.

What would be the best way to go about this so both functions can update the same lat/long in the javascript code above? Real examples will be truly appreciated.

  • 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-23T10:57:34+00:00Added an answer on May 23, 2026 at 10:57 am

    What Chris said is correct. You want to dynamically update the value from the server. Putting the code where you have it now just does it when the page is loaded, you need to use an AJAX request to keep asking the server for the latest value.

    What you need to do is make another Django View that just returns the latitude and longitude, JSON being the easiest way (i.e. in the form {“latitude”: 12.2, “longitude”: 11.1}).

    Your view will do the following:

    1. Get latitude/longitude values from models
    2. Convert to JSON format
    3. Return a HTTPResponse object using render_to_response or whatever

    On your client side, here is an example using the jQuery Javascript library to do an AJAX request:

    <script type="text/javascript">
    
    
    //Run When page first loads
    map.setCenter(new f.LatLng{{lat_long}}, 11);
    
    
    var updateLatLng = function () {
        $.ajax({
           type: "GET",
           url: "/url/to/latlng/view",
           data: "mapID=7", //Whatever extra parameters you need will go here
           success: function(data) {
             //This is run when we get data back from the server,
             //If you send back the data in JSON format
             //Then you can access the data using "data.latitude" and "data.longitude"
             map.setCenter(new f.LatLng(data.latitude, data.longitude});
           }
         });
    };
    
    //Call updateLatLng every two seconds
    window.setInterval(updateLatLng , 2000);
    
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of template HTML that is returned from a Javascript function:
I have a map that is not displaying. The page loads all the controls
I have a JavaScript function that takes two required parameters and then arbitrarily many
Is it possible to have JavaScript compute a timestamp returned from PHP's time() function
I've been writing some jQuery functions that have JavaScript variables and looping, etc inside
I currently have a map mashup that has locations that I'm populating from my
I have noticed that, from Google Maps page, you can get an embed link
I have a page where I want to display some points on map. I
I have a javascript rich page that is passing a large JSON formatted to
I have an mvc3 web page that takes a url parameter representing a date,

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.