ovim

需求说明

输入经纬度,得到城市名

挑选API

使用高德逆地理编码API,点击查看文档

demo

<?php
      /**
     * 根据输入的经纬度返回城市名称
     * @param $longitude 终点坐标(经度)
     * @param $dimension 终点坐标(纬度)
     * @return string
     */
    public function getCity($longitude,$dimension)
    {
        $location = $longitude . \',\' . $dimension;//坐标
        $key = \'6b3*************************6995\';//高德地图key-web
        $curl = \'https://restapi.amap.com/v3/geocode/regeo?output=json&location=\' . $location . \'&key=\' . $key . \'&radius=1000&extensions=base\';
        $content = file_get_contents($curl);
        $result = json_decode($content, true);
        if ($result[\'status\'] == 0) {
            return \'接口请求错误,请检查参数是否正确\';
        } else {
            $city = $result[\'regeocode\'][\'addressComponent\'][\'city\'];
            return $city;
        }
    }

分类:

技术点:

相关文章:

  • 2021-10-02
  • 2021-08-05
  • 2021-06-29
  • 2021-08-05
  • 2021-08-05
  • 2021-09-04
  • 2021-08-05
  • 2021-11-07
猜你喜欢
  • 2021-05-12
  • 2021-08-15
  • 2021-11-30
  • 2021-08-05
  • 2022-02-28
相关资源
相似解决方案