Why HTML5 Geolocation? - html

Why does HTML5 geolocation let you share your location? What is main purpose of using geolocation, as you can get the location with IP address as well. Is there any difference between these two methods?
I'm asking because geolocation requires the user's permission and also doesn't work on all browsers.

HTML5 GeoLocation tends to be much more accurate than IP-based GeoLocation.
IP-based GeoLocation depends on databases associated with ISPs to figure out where you are. This doesn't work well when your ISP services a very large area and gives out dynamic IP addresses. The address in one town today might be 100 miles away tomorrow. Furthermore, those databases are usually not updated frequently. If your ISP sells off blocks of IPs or moves them to a new town, the database may still incorrectly think you're somewhere else.
HTML5 location uses services provided by your browser to figure out where you are. If your computer has GPS built-in (such as on many mobile devices and some laptops), it will know exactly where you are. This makes it much more useful for webapps that have a navigation or location component. For devices without GPS, it can often provide a very good approximation based on nearby known wireless signals and other factors, such as tracing what routers your computer goes through when connecting to the internet. The exact implementation depends on the computer, what hardware it has available, and how the browser chooses to do things.
For example, when I check an IP-based location service, it says that I'm in a particular large city in the same general area that I live in, but it's actually about 50 miles away.
When I use an HTML5 location based service to figure out where I am, it's only off by about 20 blocks.
If you're developing a webapp which needs location data, try using HTML5 GeoLocation if at all possible. Set up a fallback, so that if HTML5 location fails, you can use an GeoIP solution instead. This way, you will get optimal accuracy on supported browsers and devices, but will still have a solution in place when the HTML5 data are not available.
If you used the geolocation-javascript project from Google Code, you could use the following code:
//determine if device has geo location capabilities
if(geo_position_js.init()){
geo_position_js.getCurrentPosition(success_callback,error_callback);
}
else{
// use an AJAX request to look up the location based on IP address
}

Geolocation is a lot more precise than IP address, though both can be faked.
IP address just gives you country and general region.
Geolocation gives you:
Geographic coordinates (latitude and longitude)
Speed (assuming you're on a device that can measure this; most tablets and smartphones can)
Altitude (this is also dependent on the device)
Degrees clockwise from north (again, assuming the device supports this)
http://diveintohtml5.ep.io/geolocation.html has some good info on geolocation and the HTML5 geolocation API. Here's the W3C Candidate Recommendation.

Obtaining a user's location through the IP-address is by far not as accurate. The IP-address' location is mostly based on the location of the actual server, which can be requested. Often this is far away from the actual user's location, so it only provides the basic region.
HTML5 geolocation on the other hand is more precise, but the user's information is used to determine the location and often also speed along with some other things. This is based on the device's GPS if available, and otherwise on information entered by the user. Clearly this is way more accurate. Both methods can be faked though.

Getting location by IP address only gives a vague location (it is rarely any more accurate than to town, and often much less accurate than that, depending on your location and ISP).
It is also sometimes completely inaccurate: if I use a VPN to connect to my company network, I will show up as being at their office because I will have an IP address from the office, but I could actually be connecting from anywhere in the world.
HTML5 geolocation can be much more accurate -- if you have a GPS receiver in your device, then it is completely accurate, but even without that, in heavily populated areas it can get your position with an accuracy of 20 meters or less by mapping the local wireless network signals. And it doesn't matter how you've connected, it will always be accurate.
Because HTML5 geolocation is so accurate, it is considered a privacy risk, so the spec states that you must give permission before a site can use your gelocation data. Also, not all browsers or machines may be capable of providing the gelocation data. The website therefore must be able to cope with users who do not provide it, and cannot rely on it being provided.
IP address location doesn't have this kind of restriction because the location mapping is done by the server using publically available IP location mapping data. The end user cannot avoid giving out their IP address, so they cannot prevent the website mapping them using it.
So the two are completely different.

The major difference that you will see is the accuracy. IP addresses only give you a very general idea of where someone might be... Geolocation will tell you exactly where they are. To read more on geolocation go here, and a demo of how accurate it can be can be is found here

HTML5 geolocation gives the client (browser) the possibility to provide the location information of the machine. This is potentially orders of magnitude more accurate than IP location. For example, the client could have actual GPS hardware installed, or be able to triangulate the location by GSM or WiFi spots. Location by IP on the other hand is very rough and somewhere between not always accurate and misleading.

Related

Getting the location of a user in AS3/Air app for mobile devices

I have an native app that I would like to store the location (just country would be fine) of where a user that logs into my app is from so I can customise some features for them.
I am using PHP as the backend. I have done some searching but nothing definitive found. Not sure how to get the IP of the device to be able to translate that to a location.
Thanks
I had to do this for my previous project. Best bet is not to rely on IP address, especially on mobile devices (my phone's IP currently has me somewhere in northern Utah when I'm actually in Phoenix). Use the GeoLocation API. That will give you the latitude, longitude position of a user which is generally fairly accurate. You can then use a GeoCoding service to determine what country they are in using reverse-geocoding. Google's GeoCoding API is fantastic and their terms were recently (April-ish) relaxed substantially making it much easier to use. I can also recommend Nominatim from OpenStreetMaps (their terms are pretty restrictive, but you can use MapQuest's Nominatim service which is pretty much free to be used however you want)
EDIT: As Pier mentioned, an ANE is required to use NetworkInfo on mobile. If you attempt to use it on mobile without the ANE, it will crash your app.
If you are set on using IPs, however, you can obtain it through the NetworkInfo class. NetworkInfo.networkInfo.findInterfaces() will give you a bunch of NetworkInterface objects. You'll be looking for InterfaceAddress. I do warn you, however, I have had difficulty in the past getting this method to work on mobile, especially iOS. Additionally, I cannot remember if it returns the network IP (i.e. 192.168.1.17) or the actual IP that is connected to the web. The local IP will obviously do you no good.
Did you look on http://www.ip2location.com/
You can use it in you php backend to translate ip to address
I would use geolocation if I were you. if its a mobile device you can use gps or cell tower (less accurate) to get their location, but if thats not an option for you and you dont have the capability of using a server-side technology like php, asp, etc. to get the ip easily, maybe this post will help: How to find the ip address in as3?

How is HTML5 geolocation API implemented in browsers?

Does every browser implement geolocation API in it's own way? Or is there some standard way all browsers do it?
And how do they do it?
When can they fail to geolocate?
An HTML5 specification simply states what a browser needs to implement in order to label itself as HTML5 compliant browser. Geolocation is a part of that very specification.
So yes, every HTML 5 compliant browser implements it in its own way.
The geolocation api needs a provider which resolves the user's location. The Location can be determined by the combined usage of many factors.
There is more than one way to figure out where you are — your IP
address, your wireless network connection, which cell tower your phone
is talking to, or dedicated GPS hardware that calculates latitude and
longitude from information sent by satellites in the sky. (link)
All of this factors however, could still be inefficient in many cases.
For eg: A user rejecting location information
or A regular PC limited to being resolved by the ip address alone. Since many ISP's use a dynamic ip and the ip to location table with the provider might not be updated with this change.

alternative to geo location html4

Is there any counterpart to geolocation(html 5) in html 4. Was there any method of determining the user's location in html4? One more question that I have is how does the geolocation get the user's location, from the IP Address or something else?
HTML5 geolocation leaves the actual means of finding the location up to the browser/client to implement. It only standardizes the Javascript API by which a website can get the location from the browser. The browser may use actual GPS hardware, known locations of nearby WiFi spots, GSM cell tower triangulation or whatever else it can. Browsers may support this standardized API without supporting any of the other parts of what is collectively called HTML5.
Before this standardization, there was no standard. There were some proprietary/plugin based things like Google Gears, but they were never widely adopted or supported. The most common way to find a client's location was, and still is, through the IP address and large databases that map IPs to known locations.
you could use json call to this http://ip-api.com/json. geolocation without gps is done though resolution of hosting and wifi/gsm cells...

geolocation showing wrong location in google map

When I use http://html5demos.com/geo to locate myself, it shows wrong location(wrong city) in FF and chrome. Any reason why this is happening
I had the same problem using Chrome on Windows, but I got it to work, at least some of the time.
I was also using the example http://html5demos.com/geo
The location was not just inaccurate, it was also in the wrong city.
I tried the same example on my iPad (Safari) and there the location was correct. My iPad is using the same WiFi network as my PC, so I then knew it was not a problem with my ISP returning the wrong location, it was to do with the browser on my PC.
I got it to show the correct location in Chrome by going into the Chrome settings and clearing the cache and cookies.
It wasn't sufficient to just select in Chrome "Tools/Clear Browsing Data/Cookies & Cache",
it was only after in Chrome I selected "Settings/Privacy/Content Settings/All Cookies and Site Data" and deleting all cookies, did the example show the correct location.
Update 1: I tried the same geolocation example the next day, and to my annoyance it was again showing the wrong city. I tried to get it to work by clearing the Chrome settings as described above and this time this solution didn't work. However, when I used the application CCleaner and selected Cleaner/Applications and cleared all of the Chrome data (internet cache, internet history, cookies and session) the geo example showed the correct location. I'm using the latest version of Chrome. Hopefully in future versions it will work more consistently.
Update 2: I tried the procedure above at a later date and couldn't get it to produce the correct location at all. It could be that the geolocation is now returning the location of my internet service provider, rather than my location, using my IP and Google Location Services. Of course this location is fairly useless. The reason why my iPad is returning the correct location is probably because it contains an inbuilt GPS. The iPad 3G / 4G have a GPS chip built in to the GSM receiver chip, whereas WiFi only models have no GPS. When 'location services' are switched off in the iPad settings, location via both GPS and IP are switched off. It would be useful just to be able to switch off the GPS on my iPad and just use IP location, but I'm not sure if that is possible.
Update 3. As I mentioned, I'm using a WiFi stick in my PC. I have noticed that when I look at the available WiFi networks (with View Available Wireless Networks) and mine is the only network, the geolocation example returns a location in a different city, but if any of my neighbours have a WiFi network in range of my PC, the geolocation example returns my exact location, to within a few metres. i.e. the geolocation in the browser is clever enough to use this extra information to locate me.
(I think the other answers to this question completely on the wrong track. The questioner states that the location was being shown in the wrong city, so the question is not to do with the location accuracy)
Different devices have different degrees of accuracy and it is important that your application be aware of the difference. A cell phone that has a GPS unit inside of it that is switched on is usually accurate within three meters. A cell phone without a GPS unit, with the GPS unit switched off to maximize battery, or at a location where the GPS can’t contact the GPS satellites will have to use cell tower triangulation to estimate the users location and is typically accurate within 3000 meters which is accurate enough to know what neighborhood the user is in but completely useless to tell them what building they are looking at.
If the user is accessing your site from a computer connected to a land-based broadband connection it can usually pinpoint the precise address by consulting a provider database and pinpointing the exact address from the DSL or cable provider.
To get the accuracy of the location information, you can query the accuracy property on the coords object. The accuracy property isn’t exact by any means but it will give your application a good sense as to whether or not you have a nearly precise position or a neighborhood.
According to the Firefox geolocation FAQ, Firefox uses Google for location services. It sends Google the following information:
Your IP address
Information about nearby Wi-Fi access points
A random Google-assigned identifier (changed weekly)
I assume it will also use GPS data if your computer has a receiver installed, but the FAQ doesn't mention that. Maybe because there's no need to use Google's sever if you have GPS data available.
I assume that Chrome, as a Google product, is using the same geolocation database.
As for why you're getting incorrect answers, that would reside in Google's database. There are most definitely errors in there. For instance, my office computer shows up in Mexico city even though my IP address and the IP address of my employer's proxy server are both in Plano, Texas, and all other IP-to-location databases have this correct (taken from the registered whois data for the address.)
Here are two Google pages that they claim will help, although they haven't done a thing for me yet:
https://support.google.com/websearch/answer/873
https://support.google.com/websearch/contact/ip
The latter (contact/ip) is a form for reporting Google location problems that manifest as Google redirecting you to the wrong country's home page. They say it may take over a month to correct the database. I've been waiting nearly two months with no luck.
There are Firefox add-ons that can be used to force your browser to report a specific location. They're meant for debugging location-aware web services, but they could also be used in a case like this, where the normal method isn't working.
I think if you could user the the method watchPosition() instead of getCurrentPosition() the coordinates will be updated too much which will produce a better result
note : it's better to use another browser other than chrome it doesn't support the watchPosition() method good enough
I figured it out. Every mobile phone has its location mode default to High Accuracy. High Accuracy uses GPS, Wi-Fi, Bluetooth, or mobile Networks to determine location.
This might be a challenge as there are many variables to getting a device's location.
The solution will be to change the location mode from High Accuracy, to Device only or GPS only.
Device only or GPS only is supposed to use just GPS and device sensors to determine location. I have tried it, it works like a charm.
Use link below to change Location mode
https://www.verizon.com/support/knowledge-base-106080/
I depends on which method is used to get your location. If it uses IP then you could show up pretty much anywhere. If it uses Wifi then it might be just be biased data.

Geolocation location changes

Over the last few days I've been working on a project involving geolocation in HTML5 and I've become familiar with the concept. This demo as well as a similar example that forms part of my project has always been accurate in determining my location to a few hundred metres. However, as of just now they all plot me as being in the nearest large city. For my project it is important that the location remains constant - what could have prompted this?
Location information can be sourced from GPS and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs, as well as user input.
It depends on what device you're testing and where it is sourcing geolocation data from. IP address lookups may change as databases are constantly updated, or a shared IP address will change depending on user input from other users. An accurate GPS fix may not be available right now. Your device temporarily switched cell towers. Etc...
If accuracy is your primary concern then use watchPosition instead of getCurrentPosition and monitor the accuracy of the returned position, only update when that drops below your threshold.