Need Geoscript to display user's city and state

Ben89

New member
Mar 30, 2007
670
4
0
So I've been looking for a script that would display a user's city and state on my landing page and have been having some problems getting them to work. Either they don't display anything or display an inaccurate city and state.

I tried using the database on maxmind.com and I also tried using this script I found on tracking202's forums, but haven't been successful.
Code:
<script src="http://www.google.com/jsapi" type="text/javascript"></script><script type="text/javascript"><!--

if (typeof(google.loader.ClientLocation.address.city) != null) {

document.write(google.loader.ClientLocation.address.city

+", "

+google.loader.ClientLocation.address.region);

} else {

document.write("Walnut Creek, CA")

}

// --></script>

Can you guys recommend any simple free, or paid scripts that can get this done? Thanks.

Oh, by the way, what do you guys see when you run that script above? Is the city + state accurate? Does it even display the city/state?
 


If you only need client side code you can use the google maps api. This requires html 5 or google gears.

code.google.com/apis/maps/documentation/javascript/basics.html#DetectingUserLocation

You may also look up "geo hashing"

I am using the paid MaxMind webservice. Cost is something like $20 for 50,000 calls. If you need server side integration it is very easy to setup and use in any language.
 
If you only need client side code you can use the google maps api. This requires html 5 or google gears.

code.google.com/apis/maps/documentation/javascript/basics.html#DetectingUserLocation

You may also look up "geo hashing"

I am using the paid MaxMind webservice. Cost is something like $20 for 50,000 calls. If you need server side integration it is very easy to setup and use in any language.

Is there a big difference between the paid version and the free version? I know the free one is supposed to be less accurate.
 
Is there a big difference between the paid version and the free version? I know the free one is supposed to be less accurate.

Why are you so set on MaxMind and Javascript to do this? It's much more efficient to just print the data to the field (which is what you're doing with JavaScript anyway) with a server-side language and be done with it using the library I linked to.

If you must use JavaScript, just call the PHP script using Ajax methods and you can do the same thing. That library I linked to is very accurate and free.

You're making this much more difficult than it has to be.
 
I missed the Geoplugin link the first time. Geoplugin looks very similar to MM and it appears to be free. The results seem to be fairly accurate as well, testing from a couple of US based servers I have access to. I am going to take a look at it myself when my MM credits expire.

As for the difference between MM free and paid. The free version requires you to install a rather large database on your end and write the SQL. The paid web service version is more accurate (updated monthly I think) and makes using it as simple as calling a url. (The same as the service that Rexibit described.)
 
Wow this is great...I'm just wondering if there's some sort of limit in place?

The only limitation with the JavaScript version, I assume, is they use the "GeoLite City" database.

Just remember to have a fall back if the GEOIP fails to find a city/region/country.

Otherwise you'll end up with something like "Hi, my name is Jane and I live inI want to ...".

I just check to see if city is empty and strip the line "and I live in" if it is.

Also if using regions remember to use region_name and not just region. While it will show the state abbreviation for the US it will show a number/letter (eg, 01, A1) for other countries, so you end up with stupid shit like "Hi my name is Jane and I live in 01, China"