Code _php tips for adding Google Maps to IP queries

Source: Internet
Author: User
1. Before using the Google API, we need to first apply for a key, which is appended to the URL as the only indication.
2. The Google Maps API contains an address that can be queried for details of a location, such as the one in Beijing: http://maps.google.com/maps/geo?q=beijing
3. We can also add a parameter to the above address, let it output the data we want, for example, we need the data of CSV, then the address becomes http://maps.google.com/maps/geo?q=beijing&output=csv
4. So we get 4 data, the first is the HTTP return address, the second is precision, the following 2 is the coordinates, know that the left can not be positioned to a certain point, then how do we get the data back? I'll write a program below.
Copy Code code 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 the data $arr are the two values of the coordinates pointed to.
5. Now we just need to consider how to send the IP location of the query to the above URL address on the line, and one of the things that makes us happy is that Google's support for Chinese is powerful, and it can identify a string of address characters, such as: Beijing Netcom is the same, so we do not have to do any conversion, Assign the value directly to the above parameter q, and then add the API key after the address.
6. We can also choose some of the Google map of the style, so that the map more powerful, such as the satellite map can be added.

At this point, our map function to the IP query function added, I hope that my attempt to help everyone.

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.