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 8129691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:24:03+00:00 2026-06-06T08:24:03+00:00

I have problem with javascript code. I am using google maps and I am

  • 0

I have problem with javascript code. I am using google maps and I am collecting data trough from server in json format. When I check data in console window in some browser I can see that data is actually coming.

My problem is that variable is read once and I am showing it’s value in the textbox. Now when I keep receiving data variable is always the same, any idea why? And I am 100% sure that I am getting different values.

Here is the code:

function updateTrucks() {
    $.ajax({
        url: "get_data.php",
        cache: false,
        dataType: 'json',
        data: {},
        error: function(jqxhr, textStatus, errorThrown) {
            alert("Error: " + textStatus + " " + errorThrown);
        },
        success: function(data) {
        for(var i = 0; i < data.results.length; i++) {
            if(trucks.hasOwnProperty(data.results[i].id)) {
                // update position
                trucks[data.results[i].id].setPosition(new google.maps.LatLng(
                parseFloat(data.results[i].lat),
                parseFloat(data.results[i].lng)));
                trucks[data.results[i].id].speed = data.results[i].speed;
            }
            else {
                // code
            }

            google.maps.event.addListener(trucks[data.results[i].id], 'position_changed', function() {
                if(typeof tracked !== "undefined") {
                    if(this.id == tracked.id) {
                        map.panTo(this.getPosition());
                        $("#speed").val(this.speed);
                    }
                }
            });     

This line is not working correctly $("#speed").val(this.speed);

  • 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-06-06T08:24:04+00:00Added an answer on June 6, 2026 at 8:24 am

    I think you need change order of you commands while updating position, so when position_changed fired speed property will be refreshed:

    if(trucks.hasOwnProperty(data.results[i].id)) {
                    trucks[data.results[i].id].speed = data.results[i].speed;
                    // update position
                    trucks[data.results[i].id].setPosition(new google.maps.LatLng(
                      parseFloat(data.results[i].lat),
                      parseFloat(data.results[i].lng)));
                  }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with JavaScript magic. When I execute this code: var page
I have a very simple JavaScript/jquery code which won't just work correctly. The problem
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
I'm using the Google Maps javascript V3 API and I'm having problems with setting
Currently I have JavaScript that displays markers on a Google map using the Google
I have a google map in a page (Using the Javascript API v3) the
1) I have a site, using jQuery and the gMap Google Maps plugin. This
I'm using some code to extract from a Google Url the keyword of the
I don't have too much experience with JavaScript and Google Maps Api. What I
Rails, Google maps, Javascript and JSON all at once. So I apologize if this

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.