I'm looking to put a video on a website that is only accessible if you are within a certain location. I have looked briefly at location APIs but i am still unsure as to how to incorporate this concept into HTML.
Any help would be very much appreciated
You have a couple of options here, each with their pros and cons.
Firstly, you could make use of the new Geolocation additions to HTML5. This unfortunately means it won't be supported in all browsers, but to be fair all major browsers do support this (IE starting at 9+). It's always a terrible practice to exclude any set of users based on something such as a browser but it's 2012 and I can see too many logical reasons for using and substandard browser.
Anyway, using HTML5 Geolocation you can find a user's location with more accuracy than most other methods. It does however require the user to allow your site to actually get their location so this would really depend on what kind of content is being served on the page. Since the access for the video seems to be somewhat exclusive it may not be such a bad thing to have the eligible users first validate their location by allowing the browser to use HTML5 Geolocation.
The next option is the old-fashioned IP-address geolocation. This is far less accurate and would actually cost you a bit to get more accurate results. There also tends to be limits when using online databases to locate IPs so if there is a lot of traffic going to such a page you might be out of luck with this method. But there are a number of services (free and paid) that give you access to databases which can locate a user based on the IP which would of course allow you to automatically get information about a user's location without the need to first ask the user (like with HTML5 Geolocation) and if you do this directly on the server-side of your site (as opposed to something like AJAX) you can handle everything before any content is loaded on to the user's page.
The last option is a terrible one for the most part, but you could always have the users input their location. Now if your site has some sort of account system this would be a bit more reliable as you should be able to gather at least some basic data on a user's location such as country and possibly even state/region (without being too invasive with things such as a full street address). But of course users can lie and so it's a bit harder to enforce honest input of information. Without any sort of account system you would be essentially asking a user to input their location (to an extent) and then either telling them "Sorry, no soup for you!" or "Here you go, vidyas!" Most people would be able to realize they could just enter one of your valid locations in to the field and view the content.
There are potentially other solutions or even a mix of the solutions above that could be implemented. In the end though it'll come down to what you need and how you want to go about gathering such information from your user-base.
Thanks a lot, very informative stuff.
I think I will go with the HTML5 geolocation option on this basis.
I've looked around and found a lot of examples of its implementation using Google maps, which is great fun, but it's tricky identifying how exactly to implement it as sort of an 'if' function - so if the viewer is within certain coordinates then the content of the site is displayed.
There is some mention of this scattered across the web but minimal specific support, so I was wondering whether anybody could point me in the right direction?
I haven't personally messed with the new HTML5 Geolocation API much but depending on what information you need about the location these links may be your solution:
Get Country from Lat and Long: http://stackoverflow.com/questions/4...tude-longitude
Get City from Lat and Long: http://stackoverflow.com/questions/6...-get-city-name
I do apologize for not being able to post some direct code that gives you your answer, but those two links include everything you need to return a country or city name given latitude and longitude coordinates from the HTML5 Geolocation API, it just may require some slight tweaks or changes to work it in to your page/system.
Anyway, I assume that if you had the country or city it would be much easier to implement this in to an if statement since you could run it against an array of accepted (or rejected) countries or cities. It would be possible to do this with the actual coordinates but a bit more involved since you'd be dealing with all sorts of ranges that you'd have to research a bit to make sure they are accurate for the proper areas.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread