Code for adding the Google map function to IP address query

Source: Internet
Author: User

1. Before using Google APIs, we need to apply for a key and add it to the URL as a unique identifier.
2. Google map API contains an address that can query the details of a location, such as query Beijing: http://maps.google.com/maps/geo? Q = Beijing
3. We can also add a parameter after the above address to let it output the data we want, for example, we need CSV data, then the address becomes a http://maps.google.com/maps/geo? 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 paragraph Program. CopyCodeThe 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, in addition, it can recognize a string of address characters. For example, Beijing and Beijing Netcom are the same, so we don't need to perform any conversions. just assign the value to the above parameter q, then the address is followed by the API key.
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.