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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:02:15+00:00 2026-06-12T23:02:15+00:00

My code is: var myvarible = 0; wialon.util.Gis.getLocations(coordsc,function(code,responceval) { myvarible = responceval; }) console.log(myvarible);

  • 0

My code is:

var myvarible = "0";

wialon.util.Gis.getLocations(coordsc,function(code,responceval) {
    myvarible = responceval;
})

console.log(myvarible); // output is 0 

How i can fix my problem? I think while it returns response code console.log runs first. please help with my problem.

  • 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-12T23:02:16+00:00Added an answer on June 12, 2026 at 11:02 pm

    Assuming that this relies on the geolocation functionality of the browser, you can’t “fix” this problem. It’s in the nature of asynchronous coding.

    In your function wialon.util.Gis.getLocations() you pass in a callback. So after the (asynchronous) execution of this call, your callback will be executed.

    Meanwhile the rest of your code is executed, which leads to the console.log(myvarible); resulting in a 0.

    Change your coding style accordingly and put all code dependent on myvarible in the callback itself or in a function, that is called inside the callback. That way this code is only executed after myvarible is set.

    So either:

    var myvarible = "0";
    
    wialon.util.Gis.getLocations(coordsc,function(code,responceval){
      myvarible = responceval;
    
      // here comes code using myvarible
      console.log(myvarible);
    });
    

    or

    var myvarible = "0";
    
    function doStuff(){
      // here comes code using myvarible
      console.log(myvarible);
    };
    
    wialon.util.Gis.getLocations(coordsc,function(code,responceval){
      myvarible = responceval;
    
      doStuff();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Javascript Code var d = function c() { console.log(c); }; d(); // function c()
Example code: var connection = null; function onConnect(status) { im_a_big_error.log('wtf'); // Why it doesn't
I have the following code: var submitHandler = function ($link, $form, close) { var
I have the following code: var refreshId = setInterval(function() { $(#footad).html('myjshere'); }, 15500); Where
I have this code: var cadena = prompt(Cadena:); document.write(mayusminus(cadena)); function mayusminus(cad){ var resultado =
Code: var a={ value:5, test:function() { this.value=4; } } var b=someFunction( { value:5, test:function()
This is my code : var markers={}; example(); function example() { var myFunct =
Code: var connection = mongoose.createConnection('mongodb://localhost:9000/' + databaseName); connection.db.dropDatabase(function(err){ // never reach this point! debugger;
The Code: var i=0,j=0; var t1= new Array(); function createtext(){ i++; t1[i]=document.createElement('input'); t1[i].type='text'; t1[i].name='text'+i;
when I code: var a = function() { alert(44) return function(){alert(33)} }()(); is 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.