How to get the current location by IP address

Source: Internet
Author: User
Tags eval json

1, the way to use the interface:

This approach is relatively stable, and the data provided is relatively stable, providing a lot of interface, you can refer to

Http://www.hujuntao.com/api/the-ip-address-api-and-call-the-interface-method.html

Do not explain, only to explain the interface Sina provides:

Sina interface Address: http://int.dpool.sina.com.cn/iplookup/iplookup.php

There are two parameters: Format and IP

1 IP: The default is native IP when the IP value is not passed in, or the specific IP address can be specified;

2 format: The data returned to the client is formatted in JS and JSON format:

A, return JS format:

eg:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=115.29.28.108

Returned result: var Remote_ip_info = {"ret": 1, "Start": "115.28.0.0", "End": "115.29.255.255", "Country": "\u4e2d\u56fd", "Province ":" \u5317\u4eac "," City ":" \u5317\u4eac "," District ":" "," ISP ":" \u7535\u4fe1 "," type ":" \u673a\u623f "," desc ":" \u4e2d \u56fd\u4e07\u7f51\u673a\u623f\u7535\u4fe1 "};

Return the result to a JS variable, the variable value is JSON format, you can convert Unicode characters to Chinese:

var remote_ip_info = {"ret": 1, "Start": "115.28.0.0", "End": "115.29.255.255", "Country": "China", "province": "Beijing", "City": " Beijing, "District": "", "ISP": "Telecommunications", "type": "Room", "desc": "China million Network Room Telecommunications"};

B, return JSON format:

eg:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=115.29.28.108

return Result:

{"ret": 1, "Start": "115.28.0.0", "End": "115.29.255.255", "Country": "\u4e2d\u56fd", "Province": "\u5317\u4eac", "City" : "\u5317\u4eac", "District": "", "ISP": "\u7535\u4fe1", "type": "\u673a\u623f", "desc": "\u4e2d\u56fd\u4e07\u7f51\ U673a\u623f\u7535\u4fe1 "}

The returned result is directly a JSON-formatted string that can be converted to Chinese by itself:

{"ret": 1, "Start": "115.28.0.0", "End": "115.29.255.255", "Country": "China", "province": "Beijing", "City": "Beijing", "District": "", "ISP": "Telecom", "type": "Room", "desc": "China million Network Room Telecommunications"}

code example:

<div> <asp:gridview id= "Gvdetail" runat= "Server" cellpadding= "4" forecolor= "#333333" gridlines= "None"
            Width= "100%" autogeneratecolumns= "false" > <alternatingrowstyle backcolor= "White"/> <editrowstyle backcolor= "#2461BF"/> <footerstyle backcolor= "#507CD1" font-bold= "True" ForeColor = "White"/>  

Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

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.