3

I am using "http://j.maxmind.com/app/geoip.js" for multilingual site support but this link is throwing 404 error.

Here is the error

Failed to load resource: the server responded with a status of 404 (Not Found)
www.globalenglish.com/:913 Uncaught ReferenceError: geoip_country_code is not defined
chrome-extension://gllmlkidgbagkcikijiljllpdloelocn/contentscript.js:1849 www.globalenglish.com
getuid:1 GET https://api.bizographics.com/v2/getuid?api_key=422935bcbfc445d59f10758c288c…I%252bJLufjW0EE6tV4BHMF43u8yA9qpnPTK8G7tGxJuiy5ReJz%252fscH55wHNbnsJU%253d 403 (Forbidden)

enter image description here

I checked the site here for new link, this link throws 401 error.

I also checked new API here but this also did not work for me. JS Link works but geoip_country_code() is undefined

enter image description here

How to make it work again !!!! Here is fiddle

Thanks

Hitesh
  • 4,098
  • 11
  • 44
  • 82
  • 1
    It seems that this link is not available anymore, and there is an other version of geoip (2.1) available at http://js.maxmind.com/js/apis/geoip2/v2.1/geoip2.js. – Halim Qarroum Mar 04 '15 at 10:55
  • it throws error `geoip_country_code() is undefined` – Hitesh Mar 04 '15 at 12:51

3 Answers3

5

Unfortunately, Maxmind doesn't provide a geoip api through

http://j.maxmind.com/app/geoip.js

anymore. Although it provides another api as

http://js.maxmind.com/js/apis/geoip2/v2.1/geoip2.js

However it requires a domain registration etc. according to Maxmind's website. The link below is a clone of the old api and valid for around one year now.

http://geoapi123.appspot.com/

I've just used this for one of my projects in development stage for a very quick solution. But I strongly suggest you to update your code according to a trustworthy service again.

A working jsfiddle to show how things could play on here; which shows this chunk of code:

$.ajax( {
            type: 'GET',
            url: '//geoapi123.appspot.com/',
            dataType: 'script',
            cache: true,
            success: function() {
                var geo = geoip_country_code() + '|' + geoip_region_name() + '|' + geoip_city() + '|' + geoip_latitude() + '|' + geoip_longitude();
                $('#results').html(geo);
            }
        });

UPDATE: I realised this answer is still getting attraction. Please be aware it has been years since I wrote this one. The URL I shared does not seem to be working anymore. Also there are much better approaches to handle the problem now.

Süha Boncukçu
  • 913
  • 1
  • 10
  • 29
  • Can u share ur code for better understanding ... or may be creating a jsfiddle will be very useful ... thank you so much – Hitesh Mar 04 '15 at 14:48
  • hey @hitesh, sorry for being late with answer. Unfortunately, it seems maxmind doesn't provide api free anymore. Although I'm not sure with buying process this [link](https://www.maxmind.com/en/geoip2-precision-services) provides some detail about it. For jsfiddle you can refer to this [link](https://jsfiddle.net/suhaboncukcu/26v3c7p8/) I'm also updating the answer. Please mark as answer if you are pleased with the answer. – Süha Boncukçu Mar 04 '15 at 21:04
  • Can I use this for production ? – Hitesh Mar 12 '15 at 04:49
  • Unfortunately, I couldn't say that. I think you should find a more reliable source or pay to maxmind for their v2 api. (Although, I made a research and I've seen this api is working for a year now.) – Süha Boncukçu Mar 13 '15 at 11:37
2

Actually, there is a message in the console you might have missed :

Users of the GeoIP2 JavaScript API must register their domains at https://www.maxmind.com/en/javascript_domains

The loading of the library failed because a request is issued to the js.maxmind.com domain with your current hostname (fiddle.jshell.net in your case) as the referrer to ensure that the client was actually making a request from an authorized hostname.

Halim Qarroum
  • 13,985
  • 4
  • 46
  • 71
  • Yes, you must register a domain at https://www.maxmind.com/en/javascript_domains ... Or use a free-to-use library, but that is out of the scope of this answer. – Halim Qarroum Mar 04 '15 at 16:05
1

hey guys i'm using This script but i don't know why HTTPS doesn't work when i try to redirect .. it only work With HTTPS

    $.ajax({
        url: "http://api.petabyet.com/geoip",
        success: function(data) {
            switch (data.country_code) {
                case 'DE':
                    window.location.href = "https://google.com/de";
                    break;
               
                
            }
        }
    })

</script>