google maps api code to add GOOGLE map function to IP query

WBOY
Release: 2016-07-29 08:43:30
Original
1291 people have browsed it

1. Before using Google API, we need to apply for a key first and add it to the end of the URL as a unique identifier.
2. There is an address in the Google Maps API that can be used to query detailed information of a certain location, for example, querying Beijing: http://maps.google.com/maps/geo?q=beijing
3. We can also query Add a parameter after the above address to let it output the data we want. For example, if we need csv data, then the address becomes http://maps.google.com/maps/geo?q=beijing&output=csv
4 . In this way, we get 4 pieces of data. The first is the http return address, the second is the accuracy, and the last two are coordinates. If we know the left side, we can locate a certain point. So how do we get it? What about the following data? Let me write a program below.

Copy the code The code is as follows:


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


Pointers 2 and 3 in data $arr are the two values ​​of the coordinates pointed to.
5. Now we only need to consider how to pass the queried IP address to the URL address above. Another thing that makes us happy is that Google has strong support for Chinese and can recognize a string of address characters. For example: Beijing and Beijing Netcom are the same, so we don’t need to do any conversion. We just assign it directly to the parameter q above, and then add the api key after the address.
6. We can also choose some styles of Google Maps to make the map function more powerful, such as adding satellite maps, etc.
At this point, our map function has been added to the IP query function. I hope my attempt will be helpful to everyone.

The above introduces the google map api code for adding GOOGLE map function to IP query, including the content of google map api. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template