Geolocation using hostip with javascript
This is probably a very stupid question. I am trying to do geolocation to find a user's address based on their ip address using the api provided by http://www.hostip.info/use.html . I am using this in conjunction with jquery with the following code:
$.get("http://api.hostip.info/get_html.php", function(data){
alert("Data Loaded: " + data);
});
Unfortunately this doesn't work. The alert never fires, so my guess is that the call never returns. Has anyone done this before? Thanks to
source to share
If you are using the Google AJAX API, then it is really easy to get the location using the Client Location functionality - it doesn't require any cross-domain calls.
if (google.loader.ClientLocation) {
var lat = google.loader.ClientLocation.latitude;
var lon = google.loader.ClientLocation.longitude;
...
Otherwise, as others have pointed out, you will need a service that provides JSONP, or you will need to write a proxy on your server to get the data for you.
source to share
You cannot make cross-domain calls to XML data. Other sites offer a JSON interface:
http://ipinfodb.com/ip_query.php?ip=999.999.999.999&output=json
which you can use for cross-domain calling using YUI GET Utility or via JQuery.
source to share