This package
I need solution for i want to update location every 30 seconds.
I'm using this package for background geolocation updates when its working fine, but when i move my phone (iphone6) it send my location to firebase. I'm using location changes of this package because postTemplate is not working on IOS device and stoOnStillActivity:true for if activity is still it wont send location.
BackgroundGeolocation.configure({
locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
desiredAccuracy: BackgroundGeolocation.MEDIUM_ACCURACY,
stationaryRadius: 10,
distanceFilter: 10,
debug: true,
interval: 30000,
stopOnStillActivity: true,
})
This one sending location to firebase
BackgroundGeolocation.on('location', (location) => {
BackgroundGeolocation.startTask(taskKey => {
firestore()
.collection('testlocation')
.add({
name: 'DEVICE',
lat: location.latitude,
lon: location.longitude,
dat: new Date,
})
.then(() => {
console.log('Location added BITCH!')
}).catch(e => console.log(e))
console.log("Stark task started successfully", new Date, location.latitude, location.longitude)
BackgroundGeolocation.endTask(taskKey)
})
})
Related
I am new to mobile development. I am trying to access my current location in the ios simulator running IOS 14.4 and I keep getting the "Location Permission denied" error even after setting up the custom location in the simulator as suggested by some answers on this platform, here. The code that I am running is this
Geolocation.getCurrentPosition(
position => {
this.setState({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
coordinates: this.state.coordinates.concat({
latitude: position.coords.latitude,
longitude: position.coords.longitude
})
});
},
error => {
Alert.alert(error.message.toString());
},
{
showLocationDialog: true,
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 0
}
);
I have set up these permissions in my info-plist.
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Description</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Will you allow this app to always know your location?</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Do you allow this app to know your current location?</string>
I am not entirely sure what I might be doing wrong here. This is the only code currently that tries to access the location.
Is there any other reason why this error should persist even after setting the current location as the custom location in Features->Location->customlocation? as suggested by the other answers on this platform.
It's required to ask location access permission at run-time before you run code that requires location access.
react-native-permissions is the standard library for cross-platform permissions
Follow installation instruction here - https://www.npmjs.com/package/react-native-permissions
import { request, PERMISSIONS, RESULT } from "react-native-permissions";
function getUserLocation() {
Geolocation.getCurrentPosition(
(position) => {
this.setState({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
coordinates: this.state.coordinates.concat({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
}),
});
},
(error) => {
Alert.alert(error.message.toString());
},
{
showLocationDialog: true,
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 0,
}
);
}
request(PERMISSIONS.IOS.LOCATION_ALWAYS).then((result) => {
switch (result) {
case RESULTS.UNAVAILABLE:
console.log(
"This feature is not available (on this device / in this context)"
);
break;
case RESULTS.DENIED:
console.log(
"The permission has not been requested / is denied but requestable"
);
break;
case RESULTS.LIMITED:
console.log("The permission is limited: some actions are possible");
break;
case RESULTS.GRANTED:
console.log("The permission is granted");
// Permission has been granted - app can request location coordinates
getUserLocation();
break;
case RESULTS.BLOCKED:
console.log("The permission is denied and not requestable anymore");
break;
}
});
Currently trying to build a location based triggered local notification in ionic 4 - I started by using native background mode (implemented in the initialize App of app.ts) which is working and tracking user location with the watchPosition(). However I'm finding it hard to get the trigger of the local notification to work. My code that I have tried is attached, ant help would be much appreciated!
this.backgroundMode.on('activate').subscribe(() => {
console.log('activated');
const watchLocation = this.geolocation.watchPosition();
watchLocation.subscribe((data) => {
data.coords.latitude;
data.coords.longitude;
console.log('current Position', data.coords.latitude, data.coords.longitude);
this.locationNotification();
});
});
this.backgroundMode.enable();
}
locationNotification() {
this.localNotifcation.schedule({
id: 3,
title: 'Welcome to the show grounds!',
text: 'Click me to declare your entries!!',
sound: '',
trigger: {
type: 'location',
center: [53.3385394, -6.266703],
radius: 1000,
notifyOnEntry: true,
notifyOnExit: false,
single: true
},
vibrate: true,
foreground: true
});
}
I'm having a problem using firebase in my Nativescript application, when I'm using android its working great but not working with IOS. the problem is on message sending.
I'm using the push-plugin in the client side
This is the register part in the IOS client side using pushPlugin
const iosSettings:any = {
badge: true,
sound: true,
alert: true,
interactiveSettings: {
actions: [{
identifier: 'READ_IDENTIFIER',
title: 'Read',
activationMode: "foreground",
destructive: false,
authenticationRequired: true
}, {
identifier: 'CANCEL_IDENTIFIER',
title: 'Cancel',
activationMode: "foreground",
destructive: true,
authenticationRequired: true
}],
categories: [{
identifier: 'READ_CATEGORY',
actionsForDefaultContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER'],
actionsForMinimalContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER']
}]
},
notificationCallbackIOS: (message: any) => {
alert(JSON.stringify(message));
}
};
pushPlugin.register(iosSettings, (token: string) => {
// update the token in the server
alert("Device registered. Access token: " + token);
});
}
}, (errorMessage: any) => {
alert("Device NOT registered! " + JSON.stringify(errorMessage));
});
This is how i receive my token to the push notification,
after a got the token when i'm using the pusher application everything works great, i'm getting the notification in the IOS device
but the problem is when im trying to send the notification from the server!.
I get this error :
Invalid registration token provided. Make sure it matches the
registration token the client app receives from registering with FCM.
Node code in my server
var payload = {
data: {
targetId:userToken,
body: "some text"
}
};
var options = {
priority: "high",
contentAvailable: true,
timeToLive: 60 * 60 * 24
};
Admin.messaging().sendToDevice(userToken, <any>payload,options)
.then((response) => {
console.log('notification arrived successfully', response.results[0]);
})
.catch((error) => {
console.log('notification failed', error);
});
registration token for ios is not the same for android. I encountered the same wall you've encountered. You need to use https://github.com/node-apn/node-apn for IOS push notification. and firebase for android notification. You can do the logic on your backend by saving the token. with a field called type which is ios or android if ios you use node-apn and if android use sendToDevice provided by firebase.
Thats what i'm currently using with my current nativescript projects' I'm working on that involves push notification. Hope that helps you, mate.
I have been trying for hours now to get geolocation.watchPosition() to actually trigger beyond the initial first componentDidMount() trigger. I have read every guide I can find on this and as far as I can see, I am doing everything people suggest.
Here is the code:
componentDidMount() {
this.watchId = navigator.geolocation.watchPosition(
(position) => {
let region = {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
latitudeDelta: 0.02500,
longitudeDelta: 0.01000,
enableHighAccuracy: true
}
this.state.currentLatitude = region.latitude;
this.state.currentLongitude = region.longitude;
console.log("WatchPosition Triggered");
this.onRegionChangeComplete(region, region.latitude, region.longitude);
},
(error) => this.setState({ error: error.message }),
{ enableHighAccuracy: true, timeout: 5000, maximumAge: 4000, distanceFilter: 1, useSignificantChanges: false },
);
}
onRegionChangeComplete(region, lastLat, lastLong) {
this.setState({
mapRegion: region,
lastLat: lastLat || this.state.lastLat,
lastLong: lastLong || this.state.lastLong
});
}
I have that console.log in there so I can see every time this function actually triggers in the app, and it just doesn't beyond the first instance of the map screen loading. I have tried walking around, confirming that my location is tracking perfectly, but this function never, ever triggers again.
Have I missed something? I can't find anything different in any example.
Please help if you can, I am pouring hours into this problem.
So I have built an app in ionic2 that tracks the phone's current location. I have built it in android and works fine when the location is on but when I built it on iOS the app doesn't show on Privacy>Location Services and doesn't track the phone's current location.
const watchOptions = {
enableHighAccurary: true,
maximumAge:5000,
timeout: 5000
}
if(state == 'login'){
this.watch = this.geolocation.watchPosition(watchOptions).subscribe(pos => {
if(pos.coords != undefined){
console.log('tracking');
this.firebaseApp.database().ref("LOCATION").child(this.user.$key).update({
lat: pos.coords.latitude,
lng: pos.coords.longitude,
timeStamp: moment().format('MMMM Do YYYY, hh:mm A').toString(),
fName: this.user.fName,
lName: this.user.lName,
status: 'login'
});
}
});
}
else{
this.watch.unsubscribe();
}
You have to enter NSLocationWhenInUseUsageDescription-key and NSLocationAlwaysAndWhenInUseUsageDescription-key to .plist-file.
You find this file in "platforms/ios"