Reputation: 1940
I've been working on this project for a while. I found out that there any many free databases which map between IP number (sort of manipulation of the IP adress) to a long and latitude cordinates. Howerver , these database accuracy is realy bad.
I tried to merge between some databases , and to the best frequent answer or the "average" among answers.
That did improve my accuracy , but not as much as i expected .
I have another idea - using Traceroute command to figure out to the path to this target , and according to the hops on the way to determine where my target is.
I'm looking for new ideas , or some kind of protocols that will help to figure out the location. I've been thinking about public cookies , but that might be too invasive . Furthermore , a friend told me that SNMP protocol might help me , but it is highly complicated to implement.
My goal is to deteremine in which city this computer is. This is the accuray i'm aiming it.
thanks and sorry for my english!
Upvotes: 2
Views: 4927
Reputation: 91149
It cannot work reliably. E.g., take the following scenarios:
I have a VPN at my company.
With this, I can get an IP address from my company without being physically present.
Where am I? At the place of my company? Or at the other side of the world, where I spend my holidays?
I have a dialup connection to my provider.
Where am I? At the point where the dial-in node sits, or where I really am?
These two examples show that the IP address itself does not hold (and cannot hold) any geographical information. It can be related to such by experience - users enter their (dynamical?) IP address into a database, related with their current IP address, but that's all. So to say, it is inherent to the system that it cannot be exact.
If you look for the "average user", which goes online via ADSL and a dynamic IP address, you don't know how big the area is where the provider take the adresses from the same pool. After I kill my connection, the user getting this IP address next might be 50 km, 500 km or even 2000 km away from me (depending on the country you live in).
Even a fixed IP assigned to a business customer might change its location: the business moves, or it ceases to exist and the IP address gets assigned to a completely different customer.
And all this stuff will change again in the next months/years with IPv6 getting more and more popular.
Upvotes: 1
Reputation: 5668
You could use HTML5's new geolocation. Example : http://html5demos.com/geo
(taken from link above)
Code:
<script>
function success(position) {
var s = document.querySelector('#status');
if (s.className == 'success') {
// not sure why we're hitting this twice in FF, I think it's to do with a cached result coming back
return;
}
s.innerHTML = "found you!";
s.className = 'success';
var mapcanvas = document.createElement('div');
mapcanvas.id = 'mapcanvas';
mapcanvas.style.height = '400px';
mapcanvas.style.width = '560px';
document.querySelector('article').appendChild(mapcanvas);
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: false,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title:"You are here!"
});
}
function error(msg) {
var s = document.querySelector('#status');
s.innerHTML = typeof msg == 'string' ? msg : "failed";
s.className = 'fail';
// console.log(arguments);
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('not supported');
}
</script>
As for databases, I've been down that road, there isn't a perfect solution all the databases will only give you around 50 mile accuracy.
With this you could use Ajax to push the location data to your server.
Upvotes: 1