Code for adding the GOOGLE map function to IP address query

Source: Internet
Author: User
I have made an IP address query page and can find the locations of many domestic IP addresses in detail. I upgraded this page a few days ago and added a map feature to it. This feature comes from the ap

I have made an IP address query page and can find the locations of many domestic IP addresses in detail. I upgraded this page a few days ago and added a map feature to it. This feature comes from the ap

1. Before using google APIs, we need to apply for a key, Hong Kong server, and add it to the url as a unique identifier.
2. The google map api contains an address that can query the detailed information of a specific location, for example, the following :? Q = beijing
3. We can add a parameter next to the above address to output the desired data. For example, if we need csv data, the address becomes? Q = beijing & output = csv
4. in this way, we get four pieces of data. The first is the http return address, the second is the precision, and the second is the coordinate. If we know that we can not locate a certain point on the left, how can we get the following data? Next I will write a program.

The Code is as follows:


$ Url = "http://maps.google.com/maps/geo? Q = beijing & output = csv ";
$ Con = file_get_contents ($ url );
$ Arr = explode (",", $ con );


The 2 and 3 pointers in data $ arr are the two coordinate values.
5. now we only need to consider how to pass the ip address to the url address above. What makes us happy is that google has a strong support for Chinese, the Hong Kong server can also recognize a string of address characters. For example, Beijing and Beijing Netcom are the same, so we don't need to perform any conversions, directly assign the value to the above parameter q, and then add the api key to the address.
6. We can also select some google map styles to make the map more powerful, such as adding satellite maps.

So far, our map function has added the IP address query function. I hope my attempt will be helpful to you.

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.