Reputation: 39
I would like to know what the best way is to get the latitude and longitude of the user visiting my page. And i want it to work in IE as well, so html5 is out of the question :)
Thanks
Upvotes: 0
Views: 294
Reputation: 5263
Google has a great geocoding API ... http://code.google.com/apis/maps/documentation/geocoding/ ... which unlike most Geo IP based lookups, uses a number of different methods, including sensors (i.e. iPhone GPS) if available, or gears, down to simple Geo IP lookups.
Upvotes: 0
Reputation: 63588
You can use JavaScript to make a call out to this service - which will return all the major details you are looking for:
http://j.maxmind.com/app/geoip.js
It will make JavaScript functions available to you with the following info:
function geoip_country_code() { return 'CA'; }
function geoip_country_name() { return 'Canada'; }
function geoip_city() { return 'Toronto'; }
function geoip_region() { return 'ON'; }
function geoip_region_name() { return 'Ontario'; }
function geoip_latitude() { return '44.7150'; }
function geoip_longitude() { return '-76.3470'; }
function geoip_postal_code() { return ''; }
function geoip_area_code() { return ''; }
function geoip_metro_code() { return ''; }
Note the data above is just a faked example...
Upvotes: 2
Reputation: 308031
If a relatively coarse location is sufficient (usually at the city level), then a Geo IP database might be appropriate (there are several providers for those, just google it).
Note also, that those can be fooled relatively easy by proxy servers. But in most cases it should be fine.
Upvotes: 0