Home Web Front-end JS Tutorial Detailed code explanation for using the API (JavaScript interface) provided by Google to obtain the IP geographical location of website visitors_javascript skills

Detailed code explanation for using the API (JavaScript interface) provided by Google to obtain the IP geographical location of website visitors_javascript skills

May 16, 2016 pm 06:22 PM
google

First introduce the JavaScript API file

<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}.

The region code is a code used internally by MaxMind. The numbers given by the provincial administrative regions in various countries in phonetic order can be converted into administrative region names through certain methods.

Usage example:

Copy code The 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>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Google Pixel 9 and Pixel 9 Pro rumoured to gain Creative Assistant AI upon release Google Pixel 9 and Pixel 9 Pro rumoured to gain Creative Assistant AI upon release Jun 22, 2024 am 10:50 AM

Google Pixel 9 and Pixel 9 Pro rumoured to gain Creative Assistant AI upon release

Google Tensor G4 of Pixel 9 Pro XL lags behind Tensor G2 in Genshin Impact Google Tensor G4 of Pixel 9 Pro XL lags behind Tensor G2 in Genshin Impact Aug 24, 2024 am 06:43 AM

Google Tensor G4 of Pixel 9 Pro XL lags behind Tensor G2 in Genshin Impact

Google app beta APK teardown reveals new extensions coming to Gemini AI assistant Google app beta APK teardown reveals new extensions coming to Gemini AI assistant Jul 30, 2024 pm 01:06 PM

Google app beta APK teardown reveals new extensions coming to Gemini AI assistant

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Jul 01, 2024 am 07:22 AM

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

Google Pixel 9 smartphones will not launch with Android 15 despite seven-year update commitment Google Pixel 9 smartphones will not launch with Android 15 despite seven-year update commitment Aug 01, 2024 pm 02:56 PM

Google Pixel 9 smartphones will not launch with Android 15 despite seven-year update commitment

New Google Pixel desktop mode showcased in fresh video as possible Motorola Ready For and Samsung DeX alternative New Google Pixel desktop mode showcased in fresh video as possible Motorola Ready For and Samsung DeX alternative Aug 08, 2024 pm 03:05 PM

New Google Pixel desktop mode showcased in fresh video as possible Motorola Ready For and Samsung DeX alternative

Google Pixel 9 Pro XL gets tested with desktop mode Google Pixel 9 Pro XL gets tested with desktop mode Aug 29, 2024 pm 01:09 PM

Google Pixel 9 Pro XL gets tested with desktop mode

Google opens AI Test Kitchen & Imagen 3 to most users Google opens AI Test Kitchen & Imagen 3 to most users Sep 12, 2024 pm 12:17 PM

Google opens AI Test Kitchen & Imagen 3 to most users

See all articles