php查询获取经纬度的详细信息-腾讯地图

本文介绍了一个PHP类,用于通过经纬度查询腾讯地图以获取详细的区域信息,主要用于校验经纬度是否匹配指定的省市区。通过获取区域的code码进行比对,实现位置的精确验证。
摘要由CSDN通过智能技术生成
我这里的使用场景是校验所选经纬度是否所属于规定的省市区下面
获取区域code码进行比对
  1. 封装的查询类
<?php

namespace app\common\library;

/**
 * @name: 经纬度查询类
 * @author: Turbo
 * @Date: 2022-09-20 10:44:36
 */
class SelectLngLatData
{
   
    protected static $instance;
    /**
     * @var array 配置
     */
    protected $option = [];
    /**
     * @var int 当前时间
     */
    protected $time = 0;
    /**
     * @var string 错误信息
     */
    protected $errorMessage = '';

    public function __construct($lng = 0, $lat = 0)
    {
   
        $this->time = time();
        $this->option['lng'] = $lng;
        $this->option['lat'] = $lat;
    }

    private function __clone()
    {
   
        // TODO: Implement __clone() method.
    }

    /**
     * 初始化
     * @param str $lng 经度
     * @param str $lat 纬度
     * @return SelectLngLatData
     */
    public static function instance($lng = 0, $lat = 0)
    {
   
        if (is_null
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是详细的步骤: 1. 在 HTML 中地图容器和标记容器: ```html <template> <div class="map-container"> <div class="map" ref="map"></div> <div class="marker" ref="marker"></div> </div> </template> ``` 2. 在 `setup()` 函数中引入腾讯地图的 API 和样式文件,并创建地图和标记: ```javascript import { onMounted, ref } from "vue"; export default { setup() { // 引入腾讯地图 API 和样式文件 const script = document.createElement("script"); script.type = "text/javascript"; script.src = "http://map.qq.com/api/js?v=2.exp&key=YOUR_KEY_HERE"; script.onload = () => { // 创建地图和标记 const map = new qq.maps.Map(document.getElementById("map"), { center: new qq.maps.LatLng(39.916527, 116.397128), zoom: 13, }); const marker = new qq.maps.Marker({ position: map.getCenter(), draggable: true, map: map, }); // 监听标记拖动结束事件 qq.maps.event.addListener(marker, "dragend", function (event) { // 获取标记位置的经纬度信息 const latLng = marker.getPosition(); console.log("经度:" + latLng.getLng() + ",纬度:" + latLng.getLat()); }); }; document.head.appendChild(script); return {}; }, }; ``` 3. 在 `mounted()` 函数中获取地图和标记容器的 DOM 节点: ```javascript import { onMounted, ref } from "vue"; export default { setup() { // ... onMounted(() => { // 获取地图和标记容器的 DOM 节点 const mapContainer = document.getElementById("map"); const markerContainer = document.getElementById("marker"); // 设置地图和标记容器的宽度和高度 mapContainer.style.width = "100%"; mapContainer.style.height = "400px"; markerContainer.style.width = "32px"; markerContainer.style.height = "32px"; // 将标记容器作为标记的图标 marker.setIcon( new qq.maps.MarkerImage( "http://open.map.qq.com/doc/img/n_marker.png", null, null, null, new qq.maps.Size(32, 32) ) ); marker.set("offset", new qq.maps.Size(0, 0)); marker.set("iconAnchor", new qq.maps.Point(16, 16)); marker.set("shadow", new qq.maps.MarkerImage(null, null, null, null, new qq.maps.Size(0, 0))); markerContainer.appendChild(marker.get("container")); }); return {}; }, }; ``` 4. 最后在 CSS 中设置地图容器的样式: ```css .map-container { position: relative; } .map { position: relative; z-index: 1; } .marker { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 2; } ``` 这样就完成了使用腾讯地图拖动标记获取经纬度的操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值