Code to add GOOGLE maps to IP queries

  • 2020-03-31 21:00:17
  • OfStack

1. Before using the Google API, we need to apply for a key to be added after the url as a unique logo.
2. There is a Google maps API can query to a certain location details of address, such as query in Beijing: http://maps.google.com/maps/geo? Q = Beijing
3. We can also add the above address behind a parameter, make it output data we want, we need CSV data, for example, the address is http://maps.google.com/maps/geo? Q = beijing&output = CSV
The first one is the HTTP return address, the second one is the accuracy, and the last two are the coordinates. If we know the left side, we can locate a certain point, so how can we get the following data? Now let me write a program.
 
$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 values of the coordinates to which they point.
5. Now we only need to consider how to convey the location of the IP query out to go to the url above, there is also a let me happy is that Google's support for Chinese are very strong, and can identify the address of a string of characters, such as Beijing and the Beijing netcom is the same, so we're not doing what transformation, directly assigned to the above parameter q, coupled with the API key and then address behind.
6. We can also choose some Google maps styles to make maps more powerful, such as adding satellite maps.

So far, our map function is added to the IP query function, I hope my attempt to help you.

Related articles: