It turns out that the geolocation of ionic3 in my cell phone after a while starts to return the same latitude and longitude. That is to say, during 30 minutes, the geolocation calculates the latitude and longitude correctly but after a time it starts to return the same latitude and longitude. Example: during the 30 minutes returns different latitudes and longitudes. 6.25 ...- 7591929 ...
After a time always the same latitude and longitude returns. That is, 6.25489, -75.129912. It does not matter in the place where it always returns 6.25489, -75.129912. I do not know if it's a cache.
Here in the provider method I have
import { Geolocation } from '@ionic-native/geolocation';
The declared variables
public laS: any = 0;
public loS: any = 0;
In the constructor I have
constructor
(
public http: Http,
private geolocation: Geolocation
)
{
console.log('Hello GeoProvider Provider');
}
The method to get the latitude and longitude I have
lng() {
var options = {
enableHighAccuracy: true,
maximumAge: 0,
timeout: 5000
};
this.subscription = this.geolocation.getCurrentPosition(options).then((resp) => {
//alert(resp.coords.latitude);
//alert(resp.coords.longitude);
this.laS = resp.coords.latitude;
this.loS = resp.coords.longitude;
}).catch((error) => {
//console.log('Error getting location', error);
alert("Error "+error);
});
}
The previous method tried removing options to see if it calculated a different latitude and longitude. Also placing at maximumAge: 0 and it does not work either. It always returns the same.
Then in the home.ts component I import the aforementioned provider
import { GeoProvider } from '../../providers/geo/geo';
In the constructor I have
constructor
(
public navCtrl: NavController,
public geoProvider: GeoProvider
)
{}
And the method to call the function
lng()
{
this.geoProvider.lng();
}
Finally in the home.html view I have
<div>
<button ion-button color="primary" (click) = "lng()">Cacular solo latitud y longitud</button>
<div>
latitud: {{ geoProvider.laS }}
</div>
<div>
Longitud: {{ geoProvider.loS }}
</div>
</div>
I do not know where I'm making the error or if it's a problem with the geolocation plugin.