Use Google's API (JavaScript interface) to get the site visitor IP Location code detailed _javascript tips

Source: Internet
Author: User
Tags geoip maxmind
First introduce JavaScript API files

<script type= "Text/javascript" src= "Http://j.maxmind.com/app/geoip.js" ></script>

This API provides a total of 6 interfaces, Geoip_country_code () {Country Code},geoip_country_ name () {Country name},geoip_city () {city name},geoip_region () {Region code}, Geoip_latitude () {longitude},geoip_longitude () {latitude}.

Where the region code for Maxmind internal use of a code, the provincial provinces in accordance with the sequencer arranged by the number, by some means can be converted to administrative names.

Use instance:
Copy Code code as follows:

<meta http-equiv= "Content-type" cont Ent= "text/html; Charset=utf-8 "/>
<title>javascript api</title>
<script type=" Text/javascript "src=" /j.maxmind.com/app/geoip.js "></script>
<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>
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.