I'm registering locations with BackgroundGeolocation.on('location', (location) => {}); using asp.net core web api, but when I switch to the background, the format of the data is different and I get a 400 error from the server
desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
stationaryRadius: 50,
distanceFilter: 50,
notificationTitle: 'GoldStamp',
notificationText: 'Aktif(Mesai Saatlerinde)',
debug: false,
startOnBoot: true,
startForeground: true,
stopOnTerminate: false,
locationProvider: Platform.OS === "ios"
? BackgroundGeolocation.DISTANCE_FILTER_PROVIDER
: BackgroundGeolocation.ACTIVITY_PROVIDER,
interval: 1000,
fastestInterval: 5000,
activitiesInterval: 1000,
stopOnStillActivity: false,
url: API_BASE + "konum/back",
syncUrl: API_BASE + "konum/back",
httpHeaders: {
'Authorization': 'Bearer ' + this.props.AuthStore.token,
},
postTemplate: { latitude: '@latitude', longitude: '@longitude' }
1.
2.
3.
4.
"fused"}])
07-23 11:33:04.696 1643 1908 I GnssLocationProvider: Hal reported a speed in excess of ITAR limit. GPS/GNSS Navigation output blocked.
07-23 11:33:04.700 13431 13591 W unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTDeviceEventEmitter.emit(["geolocationDidChange",{"mocked":false,"timestamp":1563881584000,"coords":{"speed":99.4800033569336,"heading":90,"accuracy":20,"altitude":0,"longitude":32.7267,"latitude":39.9063}}])
07-23 11:33:04.702 13431 14856 W unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTDeviceEventEmitter.emit(["geolocationDidChange",{"mocked":false,"timestamp":1563881584000,"coords":{"speed":99.4800033569336,"heading":90,"accuracy":20,"altitude":0,"longitude":32.7267,"latitude":39.9063}}])
07-23 11:33:04.728 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:04.747 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:04.889 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:04.926 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:05.028 1643 1652 I zygote : Background concurrent copying GC freed 44419(2MB) AllocSpace objects, 96(3MB) LOS objects, 12% free, 42MB/48MB, paused 1.060ms total 135.189ms
07-23 11:33:05.072 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:05.090 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:05.259 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:05.273 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:05.383 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:05.398 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:05.400 1643 1908 I GnssLocationProvider: Hal reported a speed in excess of ITAR limit. GPS/GNSS Navigation output blocked.
07-23 11:33:05.527 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:05.543 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:05.653 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:05.669 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:05.798 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:05.812 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:05.931 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:05.942 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:06.067 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:06.082 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:06.100 1643 1908 I GnssLocationProvider: Hal reported a speed in excess of ITAR limit. GPS/GNSS Navigation output blocked.
07-23 11:33:06.104 13431 13591 W unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTDeviceEventEmitter.emit(["geolocationDidChange",{"mocked":false,"timestamp":1563881586000,"coords":{"speed":374.4599914550781,"heading":85.02999877929688,"accuracy":20,"altitude":0,"longitude":32.729198333333336,"latitude":39.9063}}])
07-23 11:33:06.105 13431 14856 W unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTDeviceEventEmitter.emit(["geolocationDidChange",{"mocked":false,"timestamp":1563881586000,"coords":{"speed":374.4599914550781,"heading":85.02999877929688,"accuracy":20,"altitude":0,"longitude":32.729198333333336,"latitude":39.9063}}])
07-23 11:33:06.219 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:06.237 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:06.351 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:06.366 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:06.467 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:06.481 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:06.619 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:06.639 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:06.753 1643 1652 I zygote : Background concurrent copying GC freed 43832(2MB) AllocSpace objects, 96(3MB) LOS objects, 12% free, 42MB/48MB, paused 416us total 133.352ms
07-23 11:33:06.760 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
07-23 11:33:06.773 13431 15044 D com.marianhello.bgloc.PostLocationTask: Posting json to url: http://192.168.0.19:5000/api/konum/back headers: {Authorization=Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMzc1IiwidW5pcXVlX25hbWUiOiI2NTU0ODI5OTA2NCIsIm5iZiI6MTU2Mzg3Nzc5MiwiZXhwIjoxNTY0NzQxNzkyLCJpYXQiOjE1NjM4Nzc3OTJ9.43Z9SxY3P_XDBBho2hhbzE8DzAdLF9x8cJDQyfuWcz4HU0jffc5dO4FL2lrWl_X0eGp2xt0X-RW5Sh6voa35Ug}
07-23 11:33:06.902 13431 15044 D com.marianhello.bgloc.PostLocationTask: Executing PostLocationTask#postLocation
On location doesn't follow postTemplate. It uses default format. That is intentional. The prefix post in property postTemplate suggest that.
EDIT. check https://github.com/mauron85/react-native-background-geolocation#location-event for location event data format.
so when I do so when accessing the server lng and lat he would call or latitude, longitude
When you're using built in http posting (options url and syncUrl), then plugin will always sent locations in format defined in postTemplate (background and foreground).
But you said, you registered BackgroundGeolocation.on('location', (location) => {}); This listener will always be called with Location Event format (not postTemplate format).
No problem when taken with BackgroundGeolocation.on('location', (location) => {}); but when I close the application I get 400 error from url
Yerleşik http gönderme (seçenekler
urlvesyncUrl) kullanırken, eklenti her zaman postTemplate'de (arka plan ve ön plan) tanımlanan biçimde konumlar gönderir.Ama sen söyledin, kaydoldun
BackgroundGeolocation.on('location', (location) => {});Bu dinleyici daima Konum Olay formatı ile çağrılacak (postTemplate formatı değil).
how postTemplate should be.how should I use the application while running in the background
` BackgroundGeolocation.on('location', (location) => {
BackgroundGeolocation.startTask(taskKey => {
axios.post(API_BASE + 'konum', {
latitude: location.latitude,
longitude: location.longitude,
}, config).then(result => {
that.setState({ uyari: '' })
}).catch(e => {
var mesaj = {
tarih: moment().format("YYYY-MM-DD HH:mm:ss"),
mesaj: e.response.data
}
this.props.AppStore.saveUyari(mesaj);
});
BackgroundGeolocation.endTask(taskKey);
});
});`
there is no problem with that. There's a problem working in the background
Hi Kaan,
You don't need to use _BackgroundGeolocation.on('location'=>{})_ . Because already set url and postTemplete. These settings work both in the background and in the foreground.
Turkish:
location event'i içinde post yapmaya ihtiyacın yok çünkü zaten url ve postTemplate vermişssin. Bu şekilde uygulama ön veya arka planda belirttiğin url e post yapacaktır.
Çok tecrübem yok ama deneyimlediğim kadarıyla bu şekilde post yapıyor. Burada dikakt etmen gereken belirlediğin yarıcap ve mesafe aralığı (stationaryRadius ve distanceFilter)
Hi Kaan,
You don't need to use _BackgroundGeolocation.on('location'=>{})_ . Because already set url and postTemplete. These settings work both in the background and in the foreground.
Turkish:
location event'i içinde post yapmaya ihtiyacın yok çünkü zaten url ve postTemplate vermişssin. Bu şekilde uygulama ön veya arka planda belirttiğin url e post yapacaktır.
Çok tecrübem yok ama deneyimlediğim kadarıyla bu şekilde post yapıyor. Burada dikakt etmen gereken belirlediğin yarıcap ve mesafe aralığı (stationaryRadius ve distanceFilter)
Thank you 👍
Turkish:
Teşekkürler
On my server the json data post process works with postman but the data that comes with postTemplate is always null
postTemplate: { lat: '@latitude', lon: '@longitude' }
Asp.net core web api
My Model
public class Location
{
public decimal lat{get;set;}
public decimal lon{get;set;}
}
My Controller Function
[HttpPost]
ActionResult getlocation([FromBody] Location location){}
data I send with postman application
{
"lat":1,
"lon":33
}
that's how it works with postman
I solved the problem. data arrives as an array, not an object
[HttpPost]
ActionResult getlocation([FromBody] List<Location> location){} --> List add
Most helpful comment
I solved the problem. data arrives as an array, not an object
[HttpPost] ActionResult getlocation([FromBody] List<Location> location){} --> List add