Yahia Mgarrech
Yahia Mgarrech

Reputation: 682

Result out of getCurrentPosition()

how can i put the position result out of the function getcurrentposition

var my_position;
        navigator.geolocation.getCurrentPosition(position);{

        });

i want that "my_position" get the result of getCurrentPosition

Upvotes: 0

Views: 274

Answers (1)

Aiias
Aiias

Reputation: 4748

Try this:

var my_position;

function success(pos) {
  my_position = Object.create(pos);
  var crd = pos.coords;

  console.log('Your current position is:');
  console.log('Latitude : ' + crd.latitude);
  console.log('Longitude: ' + crd.longitude);
  console.log('More or less ' + crd.accuracy + ' meters.');
};

navigator.geolocation.getCurrentPosition(success);

Check out the documentation for more information on navigator.geolocation.getCurrentPosition().

Upvotes: 1

Related Questions