I have a Google Map on my site and am using W3 Geolocation to detect a users location when they click a button, "Get current location". Then it should popup with the allow/deny infobar at the top of the browser window.
I don't want to prompt all my visitors for Geolocation access but do want to somehow remember if a user has already allowed the Geolocation and run Geolocation if so.
From my research this isn't possible but I'm hoping someone has ran into this situation before. The only way I can figure this can be done is setting a cookie.
Thanks!
This is not exactly what you want, but I think it can be helpful.
According to W3C draft you can try to get any cached value from browser (without user's confirmation) or fallback to custom method, if no cached value found.
Assuming user has agreed to provide geolocation, it will be cached. Example from the same W3C draft:
// Request a position. We only accept cached positions, no matter what
// their age is. If the user agent does not have a cached position at
// all, it will immediately invoke the error callback.
navigator.geolocation.getCurrentPosition(successCallback,
errorCallback,
{maximumAge:Infinity, timeout:0});
Related
After a request is to made for the user's geolocation, using either navigator.geolocation.getCurrentPosition or watchPosition, the user is shown a native permission dialog.
If the user selects "Don't Allow" to the request to share their location, the API correctly responds with a PERMISSION_DENIED code.
However, if the user were to have pressed that by accident, and wishes to clear existing settings, what steps should they follow to do so?
This seems absurd enough to warrant a question.
With Android Chrome; the user can simply press the information icon and adjust the permission.
On iOS Safari, there does not appear to be a way beyond clearing all of Safari's cache and settings; thereby closing the site they were on in the first place.
For a few clients now, I've had a request to hide the "login with Facebook" feature in China, where Facebook is blocked. There are a couple ways I can think of to do this:
1) Use device locale.
Advantage: super simple!
Disadvantage: Inaccurate— someone in China could have their device set to en_US, and someone in the US could have their phone set to zh_CN. No dice.
2) Use GPS and reverse geocoding.
Advantage: You are actually measuring if the person is currently in the territory you've marked as 'restricted'.
Disadvantage: Requires the user to give you location permissions. Unclear what to do as a fallback if the user declines permissions. Some apps don't use GPS for anything else, and adding it just for this would be overkill.
3) Use a reachability check to http://facebook.com.
Advantage: You're going beyond checking whether the user is in an arbitrary location and actually checking to see whether facebook is currently restricted. If China stops blocking Facebook, your app starts supporting it immediately.
Disadvantage: You end up hiding the login UI if you're offline (which might not be a huge problem, because Facebook login won't work offline no matter where in the world you are).
Big unknown: What happens in China when you try to log into Facebook? Does it return a 404? Redirect to another site? Google searches around this (as linked above) just return things along the lines of "how to get around the Great Firewall" rather than "here's what actually happens when it's blocked".
So, the question: What happens when you try to log into Facebook from behind China's great firewall?
Trying to access Facebook in mainland China would result in error, like 403 Forbidden or 404 Not Found.
GPS Might not be a good idea, because the GPS signal in China is drifted, and as a result many cities located on the boundary would get overlapped GPS position, including southern Shenzhen/northern Hong Kong, Zhuhai/Macau, NE China/Russia and such.
How about reading the Mobile Country Code? So that users who are using Chinese sim card in their iphone can be identified and the option for facebook login can be disabled. But this trick would not be useful on iPod/iPad. It would also affect Chinese users roaming outside their country. How about checking if the IP address belong to a Chinese ISP?
It's well known how to get geolocation, after user approval:
On my computer, with Firefox, the approval popup is displayed. But if I remember well, on some devices (iPad? phone?), geolocation is sometimes approved by default (is it correct?).
Is it possible to get geolocation if and only if it is possible silently (without user approval popup)? i.e. a popup will never appear, i.e. :
either it's possible to get geolocation without popup, then get it (phone, iPad), or it's not possible, then don't ask approval, don't get browser geolocation (then maybe I'll use IP-geolocation).
Looks like you are requesting location data from the browser, which might be more accurate but requires approval.
If you can just get the IP of the visitor, with whatever backend language you are using on your server, you can get the location data from an IP location service like https://getipdata.com.
Whilst they're not accurate to street level, you can get a good idea about the city/state/country the user is in. That is of course, if they're not using a proxy or VPN.
Example: https://getipdata.com/8.8.8.8
My iOS app wants to display the users current location. Nothing special - but to do so, the first time the app is ran (or more to the point, the first time an MKViewMap in the app is displayed, I guess...) .. the user is asked for permission (which is awesome).
eg.
Now, if the user accidentally says DON'T ALLOW or decides to (later on) give permission ... is there technically a way we can reset their previous decision and when the app is restarted, ask them again automatically when the MKViewMap is next rendered again?
The user can enable or disable that option in the setting of the iphone. To do this, user have to select the Privacy option in the Setting Menu, and then select the Location Services option and than search the desired app to whom user want to enable or disable the permission and perform desired function by switching the toggle button on or off.
As it was a Private API provided from Apple the alert cannot be shown up again. Alternatively, we can check manually and show an alert like this.
The following can be read in the Apple docs:
"...it is recommended that you always call the locationServicesEnabled class method of CLLocationManager before attempting to start either the standard or significant-change location services. If it returns NO and you attempt to start location services anyway, the system prompts the user to confirm whether location services should be re-enabled. Given that location services are very likely to be disabled on purpose, the user might not welcome this prompt."
If I understand it right the alert will pop up everytime you try to get the users location, but it's not recommended to do so.
Link to full post:
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html#//apple_ref/doc/uid/TP40009497-CH2-SW1
No you cannot do so. Rather than this, you can just check the latitude and longitude value and show alert to the user that enable the service from settings.
I have read all the posts relating to this probelm, but none of them seem to match my request close enough to help me.
I have a weather widget on a website which uses geolocation to determine the location, is it possible to automatically grant permission without the user being asked for permission?
It is up to the browser to determine whether to provide geolocation information (in the HTML5 sense; after all, you can already determine limited data from their IP address). Whilst there may be some browsers that provide the information silently, none of the mainstream ones default to this behaviour.