Using mdg:geolocalisation inside a service/Factory in AngularJS

Hello !
I am actually in full dev of an App wich have a map integration.
Actually, I am trying to get the position of the user, and dynamically refresh the position of the user while he walks.

I am using mdg:geolocalisation to get the position of the user… But I HAVE To get the position inside a service, and the only way to get the position through mdg:geolocation is inside a helpers…

Does anyone have any idea ?

What do you mean with ‘inside a service’? Just use the Javascript geolocation API on the client and call a method (to save the location to the db)?

I mean, inside a service (a factory, if you prefer)
Yes, sure, but I can’t call a method outside the helpers.

Is there a way to call a return helpers inside a service/factory ?

Hi @rollins i have a lot of experience using Geo stuff on Javascript, i dont understand what is a Service/Factory. Its an API ? a Method ?. Im confused.

But… getting away from that you can do this to set the Location:

  someFn() {
    const geolocation = (
      canUseDOM && navigator.geolocation || {
        getCurrentPosition: (success, failure) => {
          alert(`Your browser dont support this feature.`);
        },
      }
    );
    geolocation.getCurrentPosition((position) => {
      console.log(position.coords.latitude)
      console.log(position.coords.longitude)
    }, (reason) => {
      //if there is an error set some default lat,lng
      // or manage errors...
      alert(`Error: (${ reason }).`);
    });
  }

That could work in JS… But I’m currently working on AngularJS. Arg. I forgot to tell that. I’m ashamed. :frowning:

Anyway.

A service/Factory is a simplification of comunication between controller an DOM. But if you don’t use AngularJS, I doubt that you can help me through this ! :frowning: