I really searched hard for it and I didn't find an answer. The problem I am facing is, that I programmed an application for an audiotour through a city based on open street map and the geolocation api.
So the problem I am facing is, that, if I access the application via G3 from my iphone I sometimes get a totaly inadequate location, (often the same, somewhere in the city), but if I use the google maps app I get an ecaxt position. I don't understand the fact, that if I make the same call from safari and from an app, I get different results.
I use 'navigator.geolocation.watchPosition' with the following options:
enableHighAccuracy: true,
timeout: 50000,
maximumAge: 0
I would really apreciate it, if someone who also faced the problem, and has an solution for this, would help me. What also happend is, that if I opend the web application and my iphone turns in power safe mode and I reactivate it, the position gets totally crazy.
My Code is really long and complicated, but maybe this helps:
options = {
enableHighAccuracy: true,
timeout: 50000,
maximumAge: 0
};
watchID = navigator.geolocation.getCurrentPosition( function(position) {
map.setCenter(lonLat, zoom );
}, function(error) { alert('Cannot determine your location! Check if you enabled geolocation for your browser.');}, options);
watchID = navigator.geolocation.watchPosition( function(position) { Here is the function!}
geolocationError,
{
enableHighAccuracy: true,
timeout: 50000,
maximumAge: 0
}
}
);
Related
Currently, i am working on a webRTC project where you can give call and receive call.i also want to add screen share functionality to it.
can anyone provide me a good documentation link?
i am currently following the official documentation of peerJS.
i was able to do audio-video calling but stuck on the screen sharing part.
Help Me!
You need to get stream just like you do with getUserMedia and then you give that stream to PeerJS.
It should be something like this:
var displayMediaOptions = {
video: {
cursor: "always"
},
audio: false
};
navigator.mediaDevices.getDisplayMedia(displayMediaOptions)
.then(function (stream) {
// add this stream to your peer
});
I'm working with and learning about WebRTC. From what I've read, I think the solution here probably hinges on getDisplayMedia. That's also what this React, Node and peerJS tutorial suggests (though I haven't tried it myself yet).
let screenShare = document.getElementById('shareScreen');
screenShare.addEventListener('click', async () => {
captureStream = await navigator.mediaDevices.getDisplayMedia({
audio: true,
video: { mediaSource: "screen" }
});
//Instead of adminId, pass peerId who will taking captureStream in call
myPeer.call(adminId, captureStream);
})
I am opening this question and answering it myself to help other users that face the same issue.
Working with a React Native app in Android that uses the package react-native-geolocation-service, when trying to get the user to activate its location (not to allow it, to activate it), I found that the button cancel wasn't returning any errors. Here is the pop up I'm talking about:
The function I was using was the following:
Geolocation.getCurrentPosition(
(position) => {
console.log(position);
(error) => {
console.log(error.code, error.message);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
});
I was completely sure it was correct, because it was a copy from github's repo. But then, the console never logged the error.
If you are facing the same issue, check the answer below.
Turns out, the problem was that a combination of Visual Studio Code pluggins (Prettier and ESLint probably) messed up with my code. The correct code should look like this:
Geolocation.getCurrentPosition(
pos => {
// Do somehting if location activated
},
error => {
console.log(error.code, error.message);
},
{enableHighAccuracy: false, timeout: 15000, maximumAge: 10000}
);
As you can see, all of my previous code was inside the "pos" brackets, meaning that it was only entering if it was successfull. Since the error block could never get reached, I wasn't able to get the negative answer from the user.
Hope this was of use to anyone.
I am using the current vuex mutation to sync to my pouch/ couchdb which is excellent. However
As I am typing into text box I can type too fast and this can mean letters are not sent to sync, which is annoying but not a killer however if I edit in the middle and type at speed sometimes cursor will jump to the end, I want live as its live text but I would like to poll a little slower does anyone have any suggests.... there was a suggestion of using since : 'now' but that doesnt seem to slow it down
syncDB: () => {
pouchdb.replicate.from(remote).on('complete', function () {
store.commit('GET_ALL_NODES')
store.commit('GET_MY_NODES')
store.commit('GET_POSITIONS')
store.commit('GET_CONNECTIONS')
store.commit('GET_EMOJI')
// turn on two-way, continuous, retriable sync
pouchdb
.sync(remote, {
live: true,
retry: true,
attachments: true,
})
.on('change', function () {
// pop info into function to find out more
store.commit('GET_ALL_NODES')
store.commit('GET_MY_NODES')
store.commit('GET_POSITIONS')
store.commit('GET_CONNECTIONS')
store.commit('GET_EMOJI')
})
.on('paused', function () {
// replication paused (e.g. replication up to date, user went offline)
// console.log('replication paused')
})
.on('active', function () {
// replicate resumed (e.g. new changes replicating, user went back online)
//console.log('back active')
})
.on('denied', function () {
// a document failed to replicate (e.g. due to permissions)
})
.on('complete', function () {
// handle complete
})
.on('error', function (err) {
console.log(err)
})
})
},
I added a debounce via lodash to the text input which helps a lot it’s not perfect especially if you are editing in the middle of text but less jumps to the end and general start speedier typing isn’t an issue
I am faced an issue that I can't solve for a weeks.
Task: I heed to watch for a device position and its direction.
Solution: I use method as described in docs
this.watcher = navigator.geolocation.watchPosition((position) => {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
const heading = position.coords.heading;
this.setState({
latitude: latitude,
longitude: longitude,
heading: heading
});
},
(error) => {
console.log(`error: ${error}`);
},
{
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 0
});
Eevrything works fine on simulator. But on a real iOS device heading is always -1.
My project use RN 0.54. However I just created fresh project with RN 0.56 via react-native init and behavior is the same.
The thing is that in react-native-maps package user direction renders in a perfect way, so I assume that there may be some issue with React Native
Any help?
Since React Native geolocation is an extension over web geolocation (see docs),
it gets orientation(heading) as a difference between two last positions. Which is not working at low speed or when user stays (returns -1).
Which is strange, because I expected RN to get device heading from built in "compass".
Solution for ejected apps: use thirds party library react-native-heading to get device heaing even when user stays.
Solution for Expo: there should be no problem like this because Expo use built in compass instead of web geolocation.
Using Location.getHeadingAsync() I was able to get a heading direction to not be -1.
Check out this link for the expo method I am using:
https://docs.expo.io/versions/latest/sdk/location#expolocationgetheadingasync-215
I am using React Native's Geolocation API to get user's location or ask user to turn location on:
// Handle PermissionsAndroid
this.watchID = navigator.geolocation.watchPosition(
(position) => {
// Update position
},
(error) => {
switch (error.code)
{
Case 1: {
// Ask user to turn on Location (Permission has already been asked for)
}
}
}
);
Now, I want to retry the watchPosition if user ever turned location on at some later point.
Using AppState, I tried getting an event if user started to interact with the notification bar (maybe user is trying to turn on Location). But it only calls back if application is sent to background or is activated again (but not during notification bar interactions).
Since Geolocation conforms with W3 standards, I tried searching for solutions in web development world. But the only solution that I found, was using iFrame which is browser-only.
Also, a non-elegant solution would be to setInterval (say every 5 seconds) and then clearInterval only if a position has been returned.
Is there a proper way to do this?
You should initiate the flow by getting the current location first, then create the watch. The following is from the Geolocation docs.
navigator.geolocation.getCurrentPosition(
(position) => {
if (position) {
//Handle first position
}
},
(error) => (console.log(error)),
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);
this.watchID = navigator.geolocation.watchPosition((position) => {
if (position) {
// Handle new position
}
});
I've found this recovers from location errors itself, as well as handling permission requests (tested on iOS 10).