


PHP uses Tencent Map to obtain the coordinates of the specified address: longitude and latitude (image, text + video)
This article mainly introduces to you the specific method of PHP using Tencent Map to obtain the coordinates of a specified address.
In the previous article [How to create a key using Tencent Map to obtain the specified address coordinates using PHP], we have already introduced to you how to apply to create a key (developer key). So below we will combine specific code examples to introduce in detail how PHP uses Tencent Maps to obtain specified coordinates, that is, longitude and latitude.
<?php // 腾讯地图 $address = '合肥政务区潜山路888号'; $url = "http://apis.map.qq.com/ws/geocoder/v1/?address=$address&key=QAKBZ-Y4OC2-4H7UY-CYDNW-NEYV2-K2FSN"; // 初始url会话 $ch = curl_init(); // 设置url传输选项 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 执行url会话 $data = curl_exec($ch); $map = json_decode($data); var_dump($map); $location = $map->result->location; echo "经度:".$location->lng."<br/>";// 经度 echo "纬度:".$location->lat."<br/>";// 纬度
Here we define an address $address and a link $url. It should be noted that there are two important parameters in this link, one is the defined $address, and the other is the key created by ourselves (development or key). Then initialize the cURL session through the curl_init function in PHP, and use the curl_setopt function to set the cURL transfer options. Then use the curl_exec function to execute the cURL session.
Then we convert the obtained url data into json format through the json_decode function.
Finally we can get the corresponding location coordinates.
Access through the browser, the result is as follows:
As shown in the figure, we obtain the longitude and latitude of the specified address.
This article is about the specific method of using Tencent Maps to obtain specified coordinates in PHP. It is also very simple, so I hope it will be helpful to friends in need!
If you want to know more about PHP, you can follow the PHP Chinese website PHP Video Tutorial, everyone is welcome to refer to and learn!
The above is the detailed content of PHP uses Tencent Map to obtain the coordinates of the specified address: longitude and latitude (image, text + video). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.
