Home Backend Development PHP Tutorial google maps api code to add GOOGLE map function to IP query

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

Jul 29, 2016 am 08:43 AM

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.

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

Announcement of 2025 PHP Situation Survey

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

See all articles