0

I am trying to use function below in chrome extension:

    function findMe(){
    if( navigator.geolocation ){
        navigator.geolocation.getCurrentPosition(alert("YES"), alert("NO"));
    }
}

And I get alert "NO", getCurrentPosition dosen't working, how to solve it?

Dmitrii Sorin
  • 3,855
  • 4
  • 31
  • 40
Marcin Kostrzewa
  • 565
  • 4
  • 11
  • 24
  • See my answer at this post: http://stackoverflow.com/questions/13386996/navigator-geolocation-getcurrentposition-not-updating-in-chrome-mobile/17540468#17540468 – surfealokesea Jul 09 '13 at 05:22

1 Answers1

1

getCurrentPosition() accepts 2 arguments, which MUST be functions. So you should pass functions as arguments.

The working code:

navigator.geolocation.getCurrentPosition(function(position) {
    console.log(position);
}, function(positionError) {
    console.error(positionError);
});

See also: http://diveintohtml5.info/geolocation.html

Dmitrii Sorin
  • 3,855
  • 4
  • 31
  • 40
  • 1
    and BTW there's a chrome permission "geolocation" which will return user's geolocation without asking for user's permission. – Dmitrii Sorin Sep 15 '12 at 22:11