Is there a JavaScript script that determines the geographical location of the visitor? I need one to determine that and depending on there location run 1 of about 5 different JavaScript scripts. How do i do this? Does someone know were i can can a script to do this or could someone write one. I am not very good at Javascript so i cant write my own

Recommended Answers

All 5 Replies

That was what i was aiming for something that did it by ip address. I will be using php but is this possible without php? This script still does not do what i want though.

yes, you can use ajax, query the webservice with ajax, when you get the location information in your xmldocument object. you can run your javascript code accordingly.

is there a script already made somewhere?

Is there a JavaScript script that determines the geographical location of the visitor? I need one to determine that and depending on there location run 1 of about 5 different JavaScript scripts. How do i do this? Does someone know were i can can a script to do this or could someone write one. I am not very good at Javascript so i cant write my own

Mozilla is working on getting location into the browser:
http://labs.mozilla.com/2008/10/introducing-geode/

You'll need a service that does the location guessing for you at the moment.

Loki is available in JS: http://loki.com/how

You can also use an IP geocoding service such as:
http://api.hostip.info/get_xml.php?ip=12.215.42.19

Then use a proxy to get that information via javascript.
eg:
http://jsonproxy.appspot.com/proxy?url=http://api.hostip.info/get_xml.php%3Fip%3D12.215.42.19%26position%3Dtrue&callback=getLocation

or using library that does this automatically:
http://rss-javascript.googlecode.com/svn/trunk/rssclient.js

eg:

client = new RSSClient();
client.getURL('http://api.hostip.info/get_xml.php?ip=12.215.42.19', function(xml) {
// get the location from the returned xml document
});
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.