zoukankan      html  css  js  c++  java
  • 百度地图根据城市获取经纬度

    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
    <script type="text/javascript" src="https://heerey525.github.io/layui-v2.4.3/layui-v2.4.5/layui.js"></script>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=AnMOlYHxzVMkWfdjS6bFuxDk"></script>
    <script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("allmap");
    var point = new BMap.Point({$data['lng']}, {$data['lat']});
    map.centerAndZoom('成都', 11);
    map.enableScrollWheelZoom(true);
    //点击返回
    var geoc = new BMap.Geocoder();
    map.addEventListener("click", function (e) {
        var pt = e.point;
        var input = document.getElementById('wd');
        var input2 = document.getElementById('jd');
        var address = document.getElementById("txtaddress");
        //返回坐标
        input.value  = pt.lng;
        input2.value = pt.lat;
        //点击坐标返回地址
        geoc.getLocation(pt, function (rs) {
            var addComp = rs.addressComponents;
            var addresstext = "";
            if (addComp.province == addComp.city) {
               addresstext = (addComp.province + addComp.district + addComp.street + addComp.streetNumber);
            }else {
               addresstext = (addComp.province + addComp.city + addComp.district +addComp.street + addComp.streetNumber);
            }
           address.value = addresstext;
        });
    });
    
    map.addControl(new BMap.NavigationControl());
    var local = new BMap.LocalSearch(map, {
       renderOptions: { map: map }
    });
    theLocation();
    function theLocation() {
        var address = document.getElementById("txtaddress").value;
        if (address != "") {
          local.search(address);
        }
    }
    //确定选择
    function Determine() {
        var wd = document.getElementById('wd');
        var jd = document.getElementById('jd');
        var address = document.getElementById("txtaddress");
        if (!wd.value || !jd.value || !address.value) {
          alert('请确定地址信息'); return false;
        }
        alert('ok');
    }
    生命不止,奋斗不息
  • 相关阅读:
    Laravel之路——缓存使用
    Laravel之路——file缓存修改为redis缓存
    PHP之路——Redis安装
    Laravel之路——事务
    Laravel框架——任务调度(cron)
    PHPStorm——配置修改
    Laravel框架——分页
    Laravel框架——Session操作
    Laravel框架——自己写的类找不到
    iwlist/iwconfig/iw命令
  • 原文地址:https://www.cnblogs.com/shione/p/15095100.html
Copyright © 2011-2022 走看看