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

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();

Related

Flutter - flutter_blue is there a way to call read/write when the characteristics known

I try to implement a flutter code that will control NIR Spectrometer via BLE.
I have a very long protocol of service and characteristic uuid pair, and I actually did the same in ionic by just using the uuid pairs and it worked fine...
Is there a way in flutter to call read/write/notify with out do all the:
List<BluetoothService> services = await device.discoverServices();
services.forEach((service) {
// do something with service
for(BluetoothCharacteristic c in characteristics) {
// save the characteristic for latter usage if needed
}
});
something like:
c = BluetoothCharacteristic(device, service_uuid, characteristic_uuid); // why there is no constructor!!
It's going to make life more easy for me!
I finally gave up, also some services that I need don't do advertisement.. So I started to use the plugin flutter_reactive_ble which gives me this option

MRTK V2 - Enable/Disable Spatial Mapping at Runtime

I know that this question has already been asked here twice, but the answers did not fix my problem. I need to enable spatial mapping on runtime. After scanning my environment I want to disable it, or hide at least the visualization of polygons, so I can save some fps. But by disabling spatial mapping I still want to have the colliders of my environment.
What I tried:
1. This example from this post did nothing.
if (disable){
// disable
MixedRealityToolkit.SpatialAwarenessSystem.Disable();
}
else
{
// enable
MixedRealityToolkit.SpatialAwarenessSystem.Enable()
}
2. Trying to disable the visualization gives me every time a nullreference. I guess GetObservers is giving null back or maybe meshOserver is null:
foreach(var observer in MixedRealityToolkit.SpatialAwarenessSystem.GetObservers())
{
var meshObserver = observer as IMixedRealitySpatialAwarenessMeshObserver;
if (meshObserver != null)
{
meshObserver.DisplayOption = SpatialAwarenessMeshDisplayOptions.None;
}
}
3. The example given by mrtk in there SpatialAwarenessMeshDemo scene, shows how to start and stop the observer. By starting everything starts fine but after suspending and clearing the observers the whole spatial map disappears, so my cursor does not align to my environment. So this is not what I need.
SpatialAwarenessSystem.ResumeObservers(); //start
SpatialAwarenessSystem.SuspendObservers();//stop
SpatialAwarenessSystem.ClearObservations();
What I have right now:
My Spatial Awareness Profile looks like this:
My code starts the spatial mapping with ResumeObservers, the foreach-loop gives me a nullreference and SuspendObserver is comment out, because it disables the whole spatial map thing:
if (_isObserverRunning)
{
foreach (var observer in SpatialAwarenessSystem.GetObservers())
{
var meshObserver = observer as IMixedRealitySpatialAwarenessMeshObserver;
if (meshObserver != null)
{
meshObserver.DisplayOption = SpatialAwarenessMeshDisplayOptions.None;
}
}
//SpatialAwarenessSystem.SuspendObservers();
//SpatialAwarenessSystem.ClearObservations();
_isObserverRunning = false;
}
else
{
SpatialAwarenessSystem.ResumeObservers();
_isObserverRunning = true;
}
Question: How do I start and stop spatial mapping the right way, so that I can save some performance and still have the colliders of the spatial map to interact with.
My specs:
MRTK v2.0.0
Unity 2019.2.0f1
Visual Studio 2017
!--Edit--inlcuding-Solution--!
1. With option #1 I was wrong. It does what its meant for, but I used it the wrong way. If you disable for example SpatialAwarenessSystem while running the spatial mapping process, it disables the whole process including the created spatial map. So after that you cant interact with the invironment.
2. What worked for me was using for the start ResumeObservers() in combination with setting display option to visible and for stopping spatial mapping the method SuspendObservers() in combination with display option none.
3. The Nullreference if fixed by rewritting and casting to IMixedRealityDataProviderAccess:
if (CoreServices.SpatialAwarenessSystem is IMixedRealityDataProviderAccess provider)
{
foreach (var observer in provider.GetDataProviders())
{
if (observer is IMixedRealitySpatialAwarenessMeshObserver meshObs)
{
meshObs.DisplayOption = option;
}
}
}
4. Performance: To get your fps back after starting an observer, you really need to disable the system via MixedRealityToolkit.SpatialAwarenessSystem.Disable();, but this will of course disable also the spatial map, so you cant interactive with it anymore.
#Perazim,
The recommendation is based on your option #3. Call ResumeObservers() to start and SuspendObservers() to stop. There is no need to call ClearObservations() unless you wish to have them removed from your scene.
The example calls ClearObservations() to illustrate what was, at the time, a new feature added to the Spatial Awareness system.
Please file an issue on GitHub (https://github.com/microsoft/MixedRealityToolkit-Unity/issues) for #1 (failure of Enable() and Disable() to impact the system). Those methods should behave as advertised.
Thank you!
David

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!

Ionic 2 native geolocation, no error thrown when location is turned off

I m using native geolocation module of an Ionic 2. Following are the part of my code
import { Geolocation } from '#ionic-native/geolocation';
..
..
getLocation(){
this.platform.ready().then(() => {
this.geolocation.getCurrentPosition().then(pos => {
console.warn("latitude = "+pos.coords.latitude);
console.warn("longitude = "+pos.coords.longitude);
}, (error) => {
console.warn("Error in fetching location");
});
});
}
I m testing app in an android phone. Everything works fine, except when the location is turned off, error is not thrown in the console. Can anybody tell me how to throw error if location service is turned off in the device??
Thanks
I have fixed myself
what I needed to do is -
this.geolocation.getCurrentPosition({timeout: 100})
I have to add timeout option as a parameter of a getCurrentPosition method.
According to Android Quirks section of plugin page:-
If Geolocation service is turned off the onError callback is invoked
after timeout interval (if specified). If timeout parameter is not
specified then no callback is called.
For more details Click Here
Infact I can also use diagnostic plugin to detect the location. Check Here

How do you make the Chrome Developer Tools only show your console.log?

It adds logs when plugins say something. It adds logs when it gets anything from the cache manifest. It logs HTTP information sometimes.
My 1 little log gets flooded by 10,000 logs I don't need or want.
Use only in development:
(function(){
var originalConsole = window.console;
window.console = {};
window.console.log = window.console.debug = window.console.error = function(){};
window.myLog = function() {
originalConsole.log.apply(originalConsole, arguments);
};
}());
This will save a local copy of the original window.console object.
It will change the original window.console object to use empty functions.
And finally it will define a global myLog function which will use the local copy of the original window.console to actually log stuff.
This way all the other code will use the useless console.log() and your code could use myLog().
on the Console tab select No info on the left Hand I have attached a screenshot here
You should update to the google chrome latest version