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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:49:38+00:00 2026-05-25T02:49:38+00:00

I’m doing next: First thing – I’m checking if I already have loaded latitude

  • 0

I’m doing next:

First thing – I’m checking if I already have loaded latitude and longitude data. If I do have, I’m saving that into array named “location”.

Second thing – if I don’t have any loaded data, I’m trying to get current position. After that, I’m trying to save latitude and longitude for current position.
And, at the end, I’m calling setMap(); function where I check location array and where I’m generating a map.

Problem:

Well, as I said it…inside “getCurrentPosition”, I’m trying to set current position into “location” array, and after that I’m trying to take those values inside setMap(); function. Here’s the problem, but only when i set “location” values inside “getCurrentPosition”. If I set “location” values manually before (from “data” array), everything works fine.
Also, when I call a setMap() function inside “getCurrentPosition”, everything works fine…but when I call it from outside, won’t work.
Can someone explain me what’s going on and what can I do?

Here’s my code:

location = new Array();
if (data.lat) {
        location['lat'] = data.lat;
        location['lng'] = data.lng;
    } else {
        if (!navigator.geolocation) {
            //
        } else {        
            navigator.geolocation.getCurrentPosition(function(position) {
                location['lat'] = position.coords.latitude;
                location['lng'] = position.coords.longitude;
            });
        }       
    }
setMap();

Thank you.

  • 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-25T02:49:38+00:00Added an answer on May 25, 2026 at 2:49 am

    You are setting a different variable inside of getCurrentPosition.
    I would suggest researching variable scope.
    Check out this question.

    –edit–

    I did not realize that the function you were using was a part of Javascript, I thought you had written/gotten it from somewhere.

    Also, I stand corrected about the scope. Since you are using an array, the scope is fine, you should be able to set it inside the callback function just fine.

    I ran your code and got some strange printouts when I did a console.log on location.
    I took a guess, and it appears that location is a reserved word. I bet that if you change the name of location to something else, your code should work fine.

    –edit–

    I should have realized this sooner actually, since location is the same as window.location, which is the browser bar location!

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am doing a simple coin flipping experiment for class that involves flipping a
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.