Detailed code for obtaining the geographic location of website visitor IP addresses using APIs (JavaScript Interface) provided by google

Source: Internet
Author: User
Tags geoip maxmind

First introduce the JavaScript API File

<Script type = "text/javascript" src = "http://j.maxmind.com/app/geoip.js"> </script>

This API provides six interfaces, geoip_country_code () {Country Code}, geoip_country _ name () {country name}, geoip_city () {city name}, geoip_region () {region code}, geoip_latitude () {longitude}, geoip_longdistance () {latitude }.

The region code is a kind of code used internally by MaxMind. The province-level administrative regions of each country are numbered in audio order. Some methods can be used to convert the code to the Administrative Region name.

Instance used:
Copy codeThe Code is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> JavaScript API </title>
<Script type = "text/javascript" src = "http://j.maxmind.com/app/geoip.js"> </script>
</Head>
<Body>
<Script type = "text/javascript">
Var area = "";
Try
{
If (geoip_city ()! = "" & Geoip_city ()! = Null)
Area + = geoip_city () + ",";
If (geoip_region_name ()! = "" & Geoip_region_name ()! = Null)
Area + = geoip_region_name () + ",";
If (geoip_country_name ()! = "" & Geoip_country_name ()! = Null)
Area + = geoip_country_name ();
}
Catch (err)
{
Area = "";
}
</Script>
</Body>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.