首页 技术 正文
技术 2022年11月18日
0 收藏 891 点赞 2,269 浏览 2070 个字

//服务器端api

extend\Map

<?php
/**
* 百度地图业务封装
*/
class Map{
/**
* 根据地址来获取经纬度
* @param $address
*/
public static function getLngLat($address) {
//拼装接口后面的参数
//http://api.map.baidu.com/geocoder/v2/?address=北京市海淀区上地十街10号&output=json&ak=您的ak&callback=showLocation //GET请求
//服务器端tw2PAd8vcGcxWi11ah39nf6oQNj2gV79
$data = [
'address' => $address,
'ak' => config('map.ak'),
'output' => 'json',
// 'ak' => 'tw2PAd8vcGcxWi11ah39nf6oQNj2gV79'
];
//http_build_query($data);
//拼接url
$url = config('map.baidu_map_url').config('map.geocoder').'?'.http_build_query($data);
// 1. file_get_contents($url);
//2. url
$result = doCurl($url);
print_r($result);
}
}
?>
==================================================================

index.php

<?php
namespace app\index\controller;
use think\Controller;
header("Content-type: text/html; charset=utf-8");
class Index extends Controller
{
public function index()
{
echo 'index';
}
public function test(){
\Map::getLngLat('石家庄市桥西区长兴街12号');
exit;
}
}
==================================================================
common.php
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------// 应用公共文件
function doCurl($url,$type=0,$data=[]){
$ch = curl_init();//初始化
//设置选项
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HEADER,0);
if($type==1){
//post
curl_setopt($ch,CURLOPT,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data); }
//执行并获取内容
$output = curl_exec($ch);
//释放curl句柄
curl_close($ch);
return $output;
}
==================================================================
extra/Map.php
<?php
/**
* 地图相关配置
*/
return [
'ak' => 'tw2PAd8vcGcxWi11ah39nf6oQNj2gV79',
'baidu_map_url' => 'http://api.map.baidu.com/',
'geocoder' => 'geocoder/v2/',
]
?>

tp5 封装百度地图api接口

tp5 封装百度地图api接口

tp5 封装百度地图api接口

tp5 封装百度地图api接口

tp5 封装百度地图api接口

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,581
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918