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.