0

Can anyone suggest how to access latitude and longitude we get from HTML5 geolocation outside of getCurrentPosition function? I don't want to show it on UI but need to send it to my spring controller. but can't access it outside the function.

Here is the code am referring too:

if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    }

    function showPosition(position) {

        $scope.PostLoc = {latitude: null, longitude: null };

        var lat = position.coords.latitude;
        var longi = position.coords.longitude;

       // var result = [lat, longi]; // it's an array
       // return result;

    }

I want this lat and longi variable to be access outside showPosition function; but not successful, can anybody help, its already been few hours and am stucked. I want to send these to my controller and call google places api.

Thank you very much. please respond.

Volker E.
  • 5,911
  • 11
  • 47
  • 64
AngryJS
  • 955
  • 5
  • 23
  • 47
  • possible duplicate of [JavaScript asynchronous return value / assignment with jQuery](http://stackoverflow.com/questions/7779697/javascript-asynchronous-return-value-assignment-with-jquery) – Quentin Apr 18 '14 at 17:53
  • @Quentin - its not! there were two responses, couldnt see them! – AngryJS Apr 18 '14 at 18:02
  • What do you mean "coulnt see them"? I can see both responses. Both explain why you can't have what you want. – Quentin Apr 18 '14 at 18:04
  • @Quentin - I cant see them on this page? are they the one just after question heading???? possible ones??? – AngryJS Apr 18 '14 at 18:06
  • https://www.evernote.com/shard/s3/sh/f96eeacb-0458-42d5-a121-9863897f2b16/2168b7921a01e326232af28f154f8a41 – Quentin Apr 18 '14 at 18:07

1 Answers1

-1

sets the value of an attribute class. thereafter any external class will be able to access this attribute. if you want you can also call a callback method to notify within another class that now has a variable value.

tschleuss
  • 56
  • 2
  • 6
  • could you please help explain a bit further, I am not that good in javascript! :( if u dont mind, a jsfiddle would be really helpful and u will get my blessings :) :) – AngryJS Apr 18 '14 at 18:08
  • it worked like this: http://stackoverflow.com/questions/23185619/how-can-i-use-html5-geolocation-in-angularjs/23185756?noredirect=1#comment35462174_23185756 – AngryJS Apr 24 '14 at 15:24