Using coordinates in ionic LaunchNavigator.navigate instead of city text - android

i'm trying to load a navigator app from my ionic application to show directions and i am using google maps, but the problem is that i am using the launchNavigator function which only accepts a string - the name of the location.
navigateLocation(){
let options: LaunchNavigatorOptions = {
start:[this.latitude,this.longitude],
app: this.launchNavigator.APP.GOOGLE_MAPS
};
this.launchNavigator.navigate('Lagos, ON', options) //here
.then(success =>{
console.log(success);
},error=>{
console.log(error);
})
}
so the Lagos option, could be london, or any other city, but what if i'm trying to get a remote location, or some other city.
why cant i just use the longitude and latitude, instead of the name..
for example
this.launchNavigator.navigate({lat:8.234345, lng:7:5644563}, 'ON', options);
something similar to that....
i dont know if anyone has done this before, please help.
thanks.

I use it like this
let destination = [lat, lng];
this.launchNavigator.navigate(destination)
.then(
success => console.log('Launched navigator'),
error => console.log('Error launching navigator', error)
);
And it shows me how do i go from where I am to the coordinates I pass.

Related

Follow user walking using react-native-maps and expo-location

I'm currently developing an university project in React Native (android app).
My goal in this component is to render a map where you can see your location, and it follows you as you walk.
Problem 1: there's a MapView props named followsUserLocation, but it only works on Apple devices. How can I do it on an android phone?
Problem 2: I'm saving the location on a state in order to reuse it everywhere else, but the Location object is empty on first render (or takes a second or two to get the location info from the emulator). Whenever I use the state where I saved that info I get an error since I have this delay.
Here's my location useEffect:
export default function App() {
const [userLocation, setUserLocation] = useState({})
const [isLoading, setIsLoading] = useState(false)
const mapRef = React.createRef();
React.useEffect(() => {
(async () => {
setIsLoading(true);
let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== "granted") {
console.log("Permission to access location was denied");
return;
}
let location = await Location.getCurrentPositionAsync({
accuracy: Location.Accuracy.Balanced,
enableHighAccuracy: true,
timeInterval: 1,
});
//console.log(location);
//console.log(location.coords.latitude);
setUserLocation(location)
setIsLoading(false);
})();
}, []);
I'm new in React Native, thank you for you patience! :)
You can't rely on followsUserLocation it's iOS-specific and not offers more flexibility.
Ideally, a Custom Location maker is required which indicates the current user's location as she moves.
The expo-location package provides Location.watchPositionAsync(options, callback) method which continuously dispatches new user location information when she moves.
With this new information, you can update the location marker in realtime.

Cordova and Tone.js "Error: buffer is either not set or not loaded" when i try to load an mp3 file

maybe you can give me a hand, I've been looking for all information, in order to solve this problem of mine, but nothing, I can't use the player with cordova ...
in practice I can't load mp3 files, whether they are both locally and remotely, I always get this error: "Error: buffer is either not set or not loaded", the files in the path are there.
I tried using Tone's oscilloscope to see if I was having trouble loading Tone, but this works fine.
Could it depend on some authorization, particular that I might be missing ?.
For example using cordova media plugin I can reproduce the audio, but I need to use Tonejs.
Do you have any ideas, what this might depend on. or what could I try to do? ...
even this simple example, after the device ready does not go:
const player = new Tone.Player("https://tonejs.github.io/audio/berklee/gong_1.mp3") .toDestination();
Tone.loaded().Then(() => {
player.start ();
});
You who have already worked with Tone and Cordova, give me hope that it can be used in some way, let me know if you have any ideas thanks in advance!
--- UPDATE:
Currently when the app starts, I behave like this (I state that it is a porting of the code developed for a website and that everything works correctly loading it, etc.):
let myLoader_File = function functionOne(test) {
var androidFixPath = cordova.file.applicationDirectory
console.log("Entered function");
return new Promise((resolve, reject) => {
let CaricatorePlayers = new Tone.Players({
Beep: androidFixPath + "sample/Beep.mp3",
Clave: androidFixPath + "sample/Clave.mp3",
}).toDestination();
resolve(
CaricatorePlayers
//"ok tutti i file sono stati caricati!"
);
reject("si è verificato un errore!");
});
};
function onDeviceReady() {
$('#fade-wrapper-flash').fadeOut(1000);
$('#fade-wrapper').fadeIn();
//attach a click listener to a start button
document.querySelector('#fade-wrapper').addEventListener('click', async () => {
await Tone.start();
console.log('audio is ready');
myLoader_File().then((res) => {
console.log(`The function recieved with value ${res}`)
MultiPlayers = res;
console.log(MultiPlayers)
try {
// Play
MultiPlayers.player("Beep").start();
$('#fade-wrapper').fadeOut();
preLoad();
} catch (error) {
console.log(error);
console.log("IN ERRORE RICARICO");
}
}).catch((error) => {
console.log(`Handling error as we received ${error}`);
console.log("IN ERRORE RICARICO");
$('#fade-wrapper').fadeIn();
});
});
}
I posted an answer, here, which also solves this problem.
I don't know if the solution is the only possible way, or the best,
in order to access the folders locally, I made these changes to the call. Using an XMLHttpRequest object
which can be used, to request data from a web server, I got a Blob object, which I then passed to the Tone player.

React Native Background Geolocation stationary not working

I'm using https://github.com/mauron85/react-native-background-geolocation and stationary is not working. My provider is DISTANCE_FILTER_PROVIDER, I followed the code
BackgroundGeolocation.on('stationary', (stationaryLocation) => {
// handle stationary locations here
console.log(stationaryLocation, 'STATIONARY')
});
but nothing is showing in the console.log, removing the BackgroundGeolocation.on('location', (location) => {}) and it shows the stationary. How is that happened? can someone helped me on how to used stationary. I'm using it in auto pause. I appreciate your help, thank you.
Try using this code.
add this to your configuration object
stationaryRadius: 50
When you are using console.log and you need to add a string variable, you need to concatenate with + sign
BackgroundGeolocation.on('stationary', (stationaryLocation) => {
// handle stationary locations here
console.log(stationaryLocation + "STATIONARY")
});
or try logging with

How to Get Location data from Photos in React Native Android 10

MediaStore.Images.Media.LATITUDE and MediaStore.Images.Media.LONGITUDE was deprecated in Android Q.
Does anyway know how we can get the Media location on React Native with expo? Basically do the below without Ejecting.
Android 10: fetch the gallery via MediaStore with location information
Thank you
import * as Permissions from 'expo-permissions';
import * as MediaLibrary from 'expo-media-library';
import Exif from 'react-native-exif'
...
MediaLibrary.getAssetInfoAsync(asset).then(function (e) {
console.log("Location is ", e.location); //always null
if (e.location) {
data.push(e);
}
});
Exif.getLatLong(asset) //doesn't get location.
.then((loc) => { console.log('Location OK: ', loc) })
.catch(msg => console.log('messages: ' + msg))
This may be an issue if you're using a real device and not an emulator.
When I use the iOS simulator, there are no issues getting the location with this method, if the image contains any location data.
const imageData = await MediaLibrary.getAssetInfoAsync(assetId);
console.log(imageData.location)
How ever, on my physical android device the locations field also resolves to null.
Even though the image i'm testing with is the same.
But when I use expo ImagePicker, location is shown if the image contains the informations.
Also, it may be unnecessary to use react-native-exif; the method getAssetInfoAsync already returns the image EXIF data.

ionic 3 geo-location not working for the second time

I have a problem using Geolocation on Android device.
I create an Ionic 3 application.
I use Geolocation ( [https://ionicframework.com/docs/native/geolocation/ 13]).
I use the sample code provided there.
The problem is that, the code works in Browser but whenever I upload it on an Android device, it does not work.
When I start the app on device the alert for location permission is prompted.
I press Allow.
Then in the android tray an icon appears that says “Searching for GPS”.
After timeout expires I got the error for timeout and no location.
The strange think is this:
If I close my app, then open google maps ( or other app using gps position ) and reopen my app works as it should.
I don’t know what to do.
The permissions are fine :
and everything was installed properly.
Can anyone help please?
i got it actually i have to pass apikey with that like
<script src="http://maps.googleapis.com/maps/api/js?key=YOUR_KEY"></script>
in the index page
without this key it sometime works but not sure everytime.
Note : this key is only generated when you have a valid gmail a/c (by providing DOB/CreditCard nos) although its free .
try this, it should work
ionic cordova run android --prod
--prod makes production build apk
import { LocationAccuracy } from '#ionic-native/location-accuracy';
declare var navigator
Above
#Component
watchPosition() {
this.locationAccuracy.request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then(
() => {
var options = {
timeout: 500,
maximumAge: Infinity
};
this.watch = navigator.geolocation.watchPosition((data) => {
let latlng: LatLng = new LatLng(data.coords.latitude, data.coords.longitude);
}, (error) => {
console.log("error watch", error)
}, options);
}
}, error => {
alert('Error requesting location permissions' + JSON.stringify(error))
});
}
}

Categories

Resources