zoukankan      html  css  js  c++  java
  • 百度地图自动获取地图中心所在城市名称

    1、编写坐标点地址解析方法

          /**
            * 坐标点地址解析
             * @param point 经纬度点对象
             */
            getGeocoderInfoByPoint:function(point){
                Geocoder.getLocation(point, function(rs) {
                       var addComp = rs.addressComponents;
                       Geocoder.point=point;
                       Geocoder.city=addComp.city;
                       Geocoder.address=addComp.province + " " + addComp.city + " "
                                + addComp.district + " " + addComp.street+ " " + addComp.streetNumber;
                });
                return Geocoder;
            }

    2、注册地图事件

               moveend:function(tagId){
                    map.addEventListener("moveend",function(e){
                        var point=map.getCenter();
                        BmapUtils.getGeocoderInfoByPoint(point);
                        $("#"+tagId).html(Geocoder.city);
                    });
                },
                dragend:function(tagId){
                    map.addEventListener("dragend",function(){
                        var point=map.getCenter();
                        BmapUtils.getGeocoderInfoByPoint(point);
                        $("#"+tagId).html(Geocoder.city);
                    });
                },
                tilesloaded:function(tagId){
                    map.addEventListener("tilesloaded",function(){
                        var point=map.getCenter();
                        BmapUtils.getGeocoderInfoByPoint(point);
                        $("#"+tagId).html(Geocoder.city);
                    });
                }

    3、调用注册事件处理

        //动态改变地图显示城市
        BmapUtils.event.moveend("curCity");
        BmapUtils.event.dragend("curCity");
        BmapUtils.event.tilesloaded("curCity");

    注:解析坐标的方法在BmapUtils下,而事件方法在BmapUtils.event下;可以在之前发布版本上添加。

  • 相关阅读:
    排序算法总结
    设计模式---(简单工厂模式,工厂模式,抽象工程模式),单例模式,代理模式,装饰器
    网易编程题——牛牛的闹钟
    Python + sqlalchemy + Pandas + Mysql 实现自动创建表,插入数据
    cucumber
    加油
    重新学习python爬虫
    python 网址
    《高兴》 贾平凹 摘抄
    funny python
  • 原文地址:https://www.cnblogs.com/boonya/p/3240557.html
Copyright © 2011-2022 走看看