zoukankan      html  css  js  c++  java
  • 百度地图(35)-GL 地址解析

    1. 地址解析和逆解析使用的是Geocoder。

     从地址到经纬度使用 getPoint,

     从经纬度到地址使用 getLocation

    2. 地址解析

     1 /**
     2  * 地址解析
     3  */
     4 function geoCode(){
     5   var myGeo = new BMapGL.Geocoder();
     6   let address = "合肥市马鞍山路合肥工业大学"
     7   myGeo.getPoint(address,function (point) {
     8     if(point){
     9       map.centerAndZoom(point,16);
    10       map.addOverlay(new BMapGL.Marker(point));
    11       console.log("X:" + point.lng + ",Y:"+point.lat);
    12       alert(point);
    13     }
    14   });
    15 };

    3. 地址逆解析

     1 /**
     2  * 地址逆解析
     3  */
     4 function geoDecode() {
     5   map.addEventListener("click",function (e) {
     6     var pt = new BMapGL.Point(e.latlng.lng,e.latlng.lat);
     7     var geoc = new BMapGL.Geocoder();
     8     geoc.getLocation(pt,function (rs) {
     9       var opts = {
    10         title:"行政区划归属",
    11         220,
    12         height:92
    13       };
    14 
    15       var addComp = rs.addressComponents;
    16       let address = '<div>省:' + addComp.province + "</div>" +
    17                     '<div>市:' + addComp.city + "</div>" +
    18                     '<div>区:' + addComp.district + "</div>" +
    19                     '<div>区:' + addComp.street + "</div>"
    20       var infoWindow = new BMapGL.InfoWindow(address,opts);
    21       map.openInfoWindow(infoWindow,pt);
    22     })
    23   });
    24 }

    4. 页面显示

    5. 源码地址

    https://github.com/WhatGIS/bdMap

  • 相关阅读:
    USACO 3.3 A Game
    USACO 3.3 Camelot
    USACO 3.3 Shopping Offers
    USACO 3.3 TEXT Eulerian Tour中的Cows on Parade一点理解
    USACO 3.3 Riding the Fences
    USACO 3.2 Magic Squares
    USACO 3.2 Stringsobits
    USACO 3.2 Factorials
    USACO 3.2 Contact
    USACO 3.1 Humble Numbers
  • 原文地址:https://www.cnblogs.com/googlegis/p/14707394.html
Copyright © 2011-2022 走看看