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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:22:41+00:00 2026-06-12T12:22:41+00:00

I am attempting to use JavaScript’s geolocation functions, but I am having issues with,

  • 0

I am “attempting” to use JavaScript’s geolocation functions, but I am having issues with, I assume, the way JavaScript works. I have found many examples on how to use the geolocation functions and they all, basically, look like this:

navigator.geolocation.getCurrentPosition(function(position){alert("Your Coordinates:\nLatitude: " + position.coords.latitude + "\nLongitude: " + position.coords.longitude);});

The above code works, but I am trying to do is something like this:

function geoMe(){
    var position = navigator.geolocation.getCurrentPosition();
    var geoLocationDiv = document.getElementById('geoLocationDiv');
    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;
    geoLocationDiv.innerHTML = latitude + "," + longitude;
}

As you can probably guess, it isn’t working. I have never been good at interpreting code that is all “jammed” together like the example, so I am VERY confused.

In looking at the example code, it looks like there is a function called “getCurrentPosition”. Now, here is where I get lost. It looks like there is a function being passed in as a parameter to getCurrentPosition that has [as a parameter] a parameter called “position”. Where did the “position” parameter come from??? I have seen where a function (without an actual function name) is used as a parameter, but it is REALLY confusing to me. Typically, I do something like:

function functionName(parameter1, parameter2, parameterN){
    function body
}

I know it is supposed to be advanced to do stuff like this, but I am a simple man, and I like my code simple, and I like my functions to have names.

So, can anybody out there help me with getting this GeoLocation stuff to work the way I want it to work? And, maybe along the way, explain this bizarre method of JavaScript functions?

Thank you, and have a great day. 🙂

  • 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-12T12:22:42+00:00Added an answer on June 12, 2026 at 12:22 pm

    This:

    function geoMe () {
        navigator.geolocation.getCurrentPosition(function ( pos ) {
            document.getElementById('geoLocationDiv').innerHTML =
                    pos.coords.latitude + "," + pos.coords.longitude;
        });
    }
    

    Live demo: http://jsfiddle.net/K6sKe/1/

    You have to pass a function object to the getCurrentPosition method. That function acts as the callback function, and is invoked when the user gives permission to access its location. In our case, our callback function is a anonymous function expression. The getCurrentPosition method is designed to call the callback passing the Position object to it. So, our function expression defines one formal argument (pos) which represents the Position object. Within the callback, we can access that Position object.

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

Sidebar

Related Questions

I'm new to Javascript and have been attempting to use a Slider called noobSlide
I'm attempting to use SignalR hubs in an application, but am having no luck
In attempting to use std::select1st from <functional> in a VS2008 project I found that
I am attempting to use the data sources pluigin for rubymine 4.0.3 but I
I have been attempting to use ASP.NET MVC remote validation for username login access
I'm attempting to use the crossfilter javascript library (in conjunction with D3.js ) to
I am attempting to use the highcharts javascript library to load charts using this
I know very little about Javascript and jQuery, and I'm attempting to use jQuery
First of all, I'm attempting to use faux namespaces in my JavaScript program like
I am attempting to use the jCorner plugin for jQuery, but falling down at

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.