Add the GOOGLE Map function to IP address query code _ PHP Tutorial

Source: Internet
Author: User
Code for adding the GOOGLE Map function to IP address query. 1. before using googleapi, we need to apply for a key and add it to the url as a unique identifier. 2. the google Map api contains a location where detailed information about a location can be queried. 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 program.

The 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.

Http://www.bkjia.com/PHPjc/322340.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/322340.htmlTechArticle1. before using google APIs, we need to apply for a key and add it after the url as a unique identifier. 2. there is a location in the google Map api that can query the details of a location...

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.