How to get location accuracy in Ionic - ionic-framework

I am trying to get the location accurate to 50m on android.
this.geolocation.getCurrentPosition(posOptions).then((resp) => {
// resp.coords.longitude
console.log(resp);
if(resp.coords.accuracy<50)
{
this.loading.hide();
}
else{
alert("The accuracy is "+ resp.coords.accuracy + " m. Location Accuracy is too low. Please Restart your phone.");
this.loading.hide();
return false ;
}
}).catch((error) => {
console.log('Error getting location', error);
});
Here I tried to submit location multiple time always it gives error
low accuracy as the location accuracy is 1500m regardless of the fact
that accuracy on android phone is set to "High Accuracy".
No matter how many time I submit the accuracy does not increase until I restart the mobile phone.
Also on the google map the location is incorrect.
How to achieve location precision?
What should be done here in order to get the accurate location without restarting or doing anything as such. The accuracy must be under 100m. Here I am using Ionic Native geolocation PLugin Link.
Please suggest a way to achieve this.
Are there any other service providing location data other than google Map api?

Related

Get rid of cached data from FlutterBlue BLE Scanning?

I'm using FlutterBlue to find my devices... but I keep getting "old" results; if I power off my device, I still get "advertisement packets" in the phone from the device when it was on...
I'd like to say "give me only what you hear on the air" so that if the time since I last heard from the device was > 5 seconds, I'll -200 the rssi and gray it out...
But I keep getting these "cached" packets that keeps clearing my timer...
My line to start the scanner is:
await flutterBlue.startScan(allowDuplicates: true);

Mapbox always visits driver location twice for the roundtrip

I'm using this example provided by mapbox for optimization by clicking on the map. However, it always visits the driver's location one more time before getting to the warehouse which is wrong.
The right attitude is definitely:
Driver location->Warehouse->Addresses->Warehouse
However, the app makes this:
Driver location->Warehouse->Addresses->Driver location->Warehouse
Here is the responsible part of the example. I don't see what causes such an attitude.
return (
'https://api.mapbox.com/optimized-trips/v1/mapbox/driving/' +
coordinates.join(';') +
'?distributions=' +
distributions.join(';') +
'&overview=full&steps=true&geometries=geojson&source=first&access_token=' +
mapboxgl.accessToken
);
I've tried to play with destination=last or any...
Any ideas what should be changed?

Firestore emulator - simulate loss of connectivity

I have an app with a real time listener setup to instantly pick up all updates on a collection. I also have some logic to pick missing documents afterwards in case my app loses its connectivity (in which case the listener would miss some documents).
I want to test this logic using the simulator, but how do I simulate the loss of connectivity? is there built-in function for that?
Actually the following page shows how to proceed in general, be it with the emulator or an actual Firestore instance:
firebase.firestore().disableNetwork()
.then(() => {
// Do offline actions
// ...
});
firebase.firestore().enableNetwork()
.then(() => {
// Do online actions
// ...
});

How to get heading accuracy of mobile devices?

I offer a service which needs the correct location and heading of the mobile device the user is accessing my service with. It was relatively easy to get the information but now I am stuck at finding out how accurate the heading I received is.
Since I'm not using any framework for this or develop in Android/iOS, where there are solutions for that problem, I'd need a solution only depending on javascript (+ 3rd party libraries).
I've found the Generic Sensor API from W3C but couldn't find any sensor which hold that information. Neither the Accelerometer-, nor the AbsoluteOrientationSensor held the needed information.
My current code looks like that..
let accelerometer = null;
try {
accelerometer = new Accelerometer({ frequency: 60 });
accelerometer.addEventListener('error', event => {
// Handle runtime errors.
if (event.error.name === 'NotAllowedError') {
console.log('Permission to access sensor was denied.');
} else if (event.error.name === 'NotReadableError') {
console.log('Cannot connect to the sensor.');
}
});
accelerometer.addEventListener('reading', (event) => {
console.log(accelerometer);
console.log(event);
});
accelerometer.start();
.. but since the problem if more of a 'finding the right tool to do the job'-type, it won't help much in better depicting my problems. Further, Google uses kind of the same functionality I'm aiming for in Google Maps, so theoretically there must be a way to get the heading accuracy.
So, in conclusion, is there any way to retrieve the heading accuracy in a simple javascript environment?
Thanks!

How to get current location in google maps using "nativescript-google-maps-sdk"?

I am building an app on nativescript+Angular2. I have downloaded the "nativescript-google-maps-sdk" plugin from npm. If I enable setMyLocationEnabled(true), I get the "my-location" button on the upper right corner of the screen and clicking it takes me to my actual location.
What I would like to do is to get these coordinates programmaticaly, because I will need them for other operations (markers, proximity values etc.).
Ran through their code, but couldn't find how they are getting this current location. gMap.getMyLocation() is deprecated, so I can't use that, based on what's written here: https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap
We should be using FusedLocationProviderApi. If this plugin isn't using it, then how does it acquire current location?
Can anyone shed some light?
mapReady(args) {
console.log("Map Ready");
var gMap = args.gMap;
gMap.setMyLocationEnabled(true);
// gMap.getMyLocation(); deprecated
// need to get current location coordinates, somehow...
}
The nativescript-google-maps-sdk plugin doesn't support getting your location from the device.
You need to get the location from nativescript-geolocation ( you are already doing that) and then pass that to the google-map.
If you check the google-maps plugin's AndroidManifest.xml, it doesn't have the permission to access the device's location.
So, as it turns out, you can get your location from your device in 2 ways:
with built in android LocationManager
with google play services location module, which uses FusedLocationProviderApi which is built on default android LocationManager
The difference, from what I've read, is that the googles' version is more advanced - it switches from different location modes (gps, wifi) automatically and saves up your battery.
So, in order to use the googles' way, we need to:
Import google play services location module (+ means newest version):
dependencies {
compile 'com.google.android.gms:play-services-location:+'
}
Then initialise the play services API:
declare var com: any;
GoogleApiClient = com.google.android.gms.common.api.GoogleApiClient;
LocationServices = com.google.android.gms.location.LocationServices;
var dis = this; // writing in typescript, so this is reference to our current component where this code will lay
// Create an instance of GoogleAPIClient.
if (this.googleApiClient == null) {
this.googleApiClient = new dis.GoogleApiClient.Builder(application.android.context)
.addConnectionCallbacks(new dis.GoogleApiClient.ConnectionCallbacks({
onConnected: function() {
console.log("GoogleApiClient: CONNECTED");
}.bind(this),
onConnectionSuspended: function() {
console.log("GoogleApiClient: SUSPENDED");
}.bind(this)
}))
.addOnConnectionFailedListener(new dis.GoogleApiClient.OnConnectionFailedListener({
onConnectionFailed: function() {
console.log("GoogleApiClient: CONNECTION ERROR");
}.bind(this)
}))
.addApi(dis.LocationServices.API)
.build();
}
this.googleApiClient.connect();