I'm trying to retrieve the geolocation on Opera browser, but I got no response or a timeout.
I have use the following:
navigator.geolocation.watchPosition
navigator.geolocation.getCurrentPosition(position => {alert('Got it');}, failure => {alert('Failed');},{ maximumAge: 30000, timeout: 30000, enableHighAccuracy: true });
I have try the following lib: https://github.com/gregsramblings/getAccurateCurrentPosition
I even use a timeout of 30 seconds (which is way too much).
But no way, I can't find a way to get my location back.
PS: it works everywhere else Windows / Mac / Android / iPhone !
If you have any idea ?
Related
I'm attempting to use HTML5 Geolocation on IE11, but despite allowing location permission, I get an error, "This site does not have permission to use the Geolocation API."
To replicate:
Open any site in IE11 (I'm user browerstack to emulate a Windows 10)
Copy/paste the following code in the console:
var options = {
enableHighAccuracy: false,
timeout: 1000000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('got your position');
}
function error(err) {
console.log(err);
}
navigator.geolocation.getCurrentPosition(success, error, options);
Click "Allow Once" when the location prompt appears
Observe the Resulting Error Message, "This site does not have permission to use the Geolocation API."
My browserstack is running IE11 version 11.1.17134.0, on a Windows 10.
Thanks in advance for your help!
After searching now for hours, I unfortunately can't find a solution to my current iOS Safari issue.
I've got a JavaScript frontent which uses jQuery.ajax to communicate with an ASP.NET MVC web server.
That works absolutely perfect on all platforms, e.g. Windows 10 with Chrome, Firefox, IE (yes, IE works), Edge. Or on a Mac with Chrome, Firefox, Safari. The place where it does not work is iOS Safari.
In my scenario, I'm sending multiple AJAX requests to the server almost at the same time. Maybe 3 to maximum 6 calls. Having a look at the Safari developer tools, the calls look like this.
They seem to take very long, but having a look at the server, they appearently never reach the backend. Also, after exactly 10 minutes, the browser runs into the timeout. Even though I have configured an AJAX timeout of 60 seconds.
My code looks pretty okay to me at the moment (written in TypeScript):
let defer: JQueryDeferred<any> = jQuery.Deferred();
this._RunningRequests++;
let settings: JQueryAjaxSettings = {
method: method,
url: this.BuildURL(controller, action, id),
contentType: 'application/json',
timeout: Timeout,
cache: false,
headers: {}
};
if (payload) {
settings.data = JSON.stringify(payload);
}
jQuery.ajax(settings)
.done((result: any) => {
if (this.DetectLogoutRedirect(result)) {
defer.reject();
location.reload(true);
return;
}
defer.resolve(result);
})
.fail((jqXHR: JQueryXHR, textStatus: string, errorThrown: string) => {
defer.reject();
this.HandleError(method, controller, action, jqXHR, textStatus, errorThrown);
}).always(() => {
this._RunningRequests--;
});
return defer.promise();
Here now the fun part. As soon as I add a delay to the call ...
let delay = this._RunningRequests * 500;
setTimeout(() => { jQuery.ajax(...) }, delay);
... which makes sure the calls are not sent quickly after each other, it works perfectly fine.
Things I've tried and found out so far:
I've set all headers for cache control plus all jQuery configurations adressing cache to false
I've added a guid-like param to every call (POST as well) to ensure the URL is always unique
As mentioned above, I've added the delay which solves the problem, but is not realy practiable
I've tried to reproduce the issue wihin the iOS Simulator. Same result.
It seems to affect POST requests only, but I'm not sure about that.
How can I fix this?
We encountered the same issue with our Single Page App as soon as it got particulary "chatty" with our API.
It appears to be caused by a bug with the DNS resolution somewhere in the iOS networking stack.
We found that by changing the DNS setting from automatic to manual on the device, and setting the DNS servers to the Google Public DNS, all XHR requests made by our app worked and we stopped getting the weird timeouts.
Here is a guide on how to change the DNS setting on an iOS device:
https://www.macinstruct.com/tutorials/how-to-change-your-iphones-dns-servers/
I'm using navigator.geolocation.getCurrentPosition() in react native and it's working fine.
But i would like to be able to react nicely if location services are turned off (a dialog box that leads the user to settings).
I found that plugin for android and i think it's going to work fine :
https://www.npmjs.com/package/react-native-android-location-services-dialog-box How should i do in iOS ?
EDIT
You can use this very well done 3rd party library
and then use it like this :
Location.getAuthorizationStatus((authorization) => {
console.log(authorization)
});
Previous answer
getCurrentPosition can take an error callback. This will be triggered if the location is not enabled.
You can do something like:
navigator.geolocation.getCurrentPosition(
(position) => {
this.setState({ position });
},
(error) => {
console.log(alert);
},
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);
You can check the docs for more informations.
All of a sudden, my Twitter widget on my website is not showing any tweets. I've checked my console log and it's returning a 400 bad request error. This was working fine only an hour ago! I have been working on this page today and probably refreshed the page 30+ times. I wonder if that had anything to do with it.
I've read other SO questions related to the same problem and some say it's a problem Twitter's end and you just have to wait. This is an issue for me. I've now got a big blank space where the widget should sit, and looks darn ugly and unprofessional!
Is there any way to detect this error and show a polite message in its place "Sorry, Twitter widget is ** crap and can't be loaded."? Or can you give me any more information?
<script charset="utf-8" src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 10,
interval: 30000,
width: 270,
height: 250,
theme: {
shell: {
background: '#111111', color: '#B000BB'
},
tweets: {
background: '#111111', color: '#999999', links: '#faadfa'
}
},
features: {
scrollbar: true, loop: false, live: true, behavior: 'all'
}
}).render().setUser('myClientsTwitterUsername').start();
</script>
I've just found the answer, so hopefully it will help others.
Apparently the Twitter widget I'm using does not use Twitter's API, thus, I'm limited to 150 requests per hour, per IP address. With the work I did on this page today, refreshing the page 30-40 times, and the widget updating every 30 seconds, it seems I have used all 150 requests and have been barred from further requests until the limit refreshes. I checked this by loading my webpage on my iPad (which uses a different IP address/network) and the widget seems fine. I also waited 1 hour and the widget came back to life on the affected network/ip.
So, I'd better start using the proper Twitter API widget.
Hope this helps somebody.
Greetings Everyone,
I am creating a web application that uses the Geolocation API to locate the end user. It works great on almost every platform I can think of except for Internet Explorer 9. Things get a little stranger though. If I have my Google Toolbar loaded into my Internet Explorer browser window, everything sails smoothly. Here is the offending chunk of code that I have been working with:
if (navigator.geolocation) {
var locationMarker = null;
navigator.geolocation.watchPosition(
function( position ){
var point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
if (!locationMarker) {
locationMarker = addMarker(
position.coords.latitude,
position.coords.longitude,
"Initial Position"
);
}
else{
updateMarker(
locationMarker,
position.coords.latitude,
position.coords.longitude,
"Updated / Accurate Position"
);
};
map.setCenter(point);
if (map.zoom < 17){
map.setZoom(17);
};
},
function( error ){
console.log( "Something went wrong: ", error );
},
{
timeout: (5 * 1000),
maximumAge: (1000 * 60 * 15),
enableHighAccuracy: true
}
);
}
else {
alert("Geolocation is not supported by this browser");
}
Whenever I access my application with Internet Explorer 9 I get the "Geolocation is not supported by this browser" alert. That is unless I have my Google Toolbar active. If the Google Toolbar is active however, then the Google Toolbar handles the permissions.
How do I get geolocation to work in IE9? My application works flawlessly in Safari, Firefox, Chrome, iOS and Android. I am totally stumped.
Thanks, Tyler Waring
user1303379,
IE9 and IE10 both support geolocation, however earlier versions of IE do not support it ( reference http://caniuse.com/#feat=geolocation ). Here is a blog post by IE about geolocation in IE9 http://blogs.msdn.com/b/ie/archive/2011/02/17/w3c-geolocation-api-in-ie9.aspx and here is a test page using navigator.geolocation.watchPosition like you are above.
For browsers that don't support geolocation you may consider using one of the geolocation polyfills listed here https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills
IE9 & IE10 ask the user if they would like to share their location http://cl.ly/image/0X0o2F0s1N03 My guess is that you may have denied access to your location at some point.
The Google Toolbar added a feature to determine geolocation back in the IE8 days http://googletoolbarhelp.blogspot.com/2010/02/google-toolbar-6413211732-for-ie.html From what you describe it sounds like the Google Toolbar started to provide geolocation since the native IE9 geolocation was denied access.