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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:15:41+00:00 2026-06-08T07:15:41+00:00

i am using the following code to access the geolocation of the blackberry device.

  • 0

i am using the following code to access the geolocation of the blackberry device. its working and showing the desire result. but i want to access the window.GlobalVar outside the body of this function. how can i access it? please help.

 navigator.geolocation.getCurrentPosition(function(position) {  
  var gps = (position.coords.latitude+position.coords.longitude);  
  window.GlobalVar = gps;
  alert (window.GlobalVar);
});

Best regards,

  • 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-08T07:15:43+00:00Added an answer on June 8, 2026 at 7:15 am

    window.GlobalVar will be accessible outside of your function.

    What’s probably going wrong here is that you’re trying to access it before it has been set, seeing as it is being set in a callback function.

    getCurrentPosition prompts the user for coordinates, but it is not a blocking call, i.e. it does not simply halt all code execution and wait for the user to make a decision.

    This means that you do not set window.GlobalVar during page load, you request it during page load, and you set it whenever the user decides to. So no matter where you call getCurrentPosition you cannot be sure that at a given point, window.GlobalVar will be set.

    If you want to be sure that window.GlobalVar is set in the script you’re running, you need to make sure that you’re running the script after the variable has been set.

    navigator.geolocation.getCurrentPosition(function(position) {  
      var gps = (position.coords.latitude+position.coords.longitude);  
      window.GlobalVar = gps;
    
      continueSomeProcess();
    });
    
    function continueSomeProcess() {
       // this code will be able to access window.GlobalVar
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hai I am using the following code to access columns in a row but
I am using the following code to access the background page function in google
I am using following code to create new wifi access point and to connect
I'm using with good results the following code to access alla of my php
I'm using pax-exam to load, activate and access osgi bundles. The following source code
When using the armcc4.1 to compiler my code, it reports following error: access/qnetworkrequest_p.h, line
I am using the following code to access a URL (the URL uses the
I am using the following code to access sdcard if mounted else using the
I am using following code to post image on Facebook wall. it's working fine.
I'm currently using the following code for thread-safe access of a variable. int gnVariable;

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.