pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<i id='nLZ0B'><tr id='nLZ0B'><dt id='nLZ0B'><q id='nLZ0B'><span id='nLZ0B'><b id='nLZ0B'><form id='nLZ0B'><ins id='nLZ0B'></ins><ul id='nLZ0B'></ul><sub id='nLZ0B'></sub></form><legend id='nLZ0B'></legend><bdo id='nLZ0B'><pre id='nLZ0B'><center id='nLZ0B'></center></pre></bdo></b><th id='nLZ0B'></th></span></q></dt></tr></i><div class="bdlrfd1" id='nLZ0B'><tfoot id='nLZ0B'></tfoot><dl id='nLZ0B'><fieldset id='nLZ0B'></fieldset></dl></div>
<legend id='nLZ0B'><style id='nLZ0B'><dir id='nLZ0B'><q id='nLZ0B'></q></dir></style></legend>

  1. <tfoot id='nLZ0B'></tfoot>

        <bdo id='nLZ0B'></bdo><ul id='nLZ0B'></ul>

    1. <small id='nLZ0B'></small><noframes id='nLZ0B'>

      Google maps JS API v3:使用 containsLocation() 獲取圓圈中

      Google maps JS API v3: get markers in circle with containsLocation() doesn#39;t work - why?(Google maps JS API v3:使用 containsLocation() 獲取圓圈中的標記不起作用 - 為什么?)
      • <bdo id='8ksa3'></bdo><ul id='8ksa3'></ul>

        <small id='8ksa3'></small><noframes id='8ksa3'>

            <tbody id='8ksa3'></tbody>
          <tfoot id='8ksa3'></tfoot>

        1. <legend id='8ksa3'><style id='8ksa3'><dir id='8ksa3'><q id='8ksa3'></q></dir></style></legend>
            1. <i id='8ksa3'><tr id='8ksa3'><dt id='8ksa3'><q id='8ksa3'><span id='8ksa3'><b id='8ksa3'><form id='8ksa3'><ins id='8ksa3'></ins><ul id='8ksa3'></ul><sub id='8ksa3'></sub></form><legend id='8ksa3'></legend><bdo id='8ksa3'><pre id='8ksa3'><center id='8ksa3'></center></pre></bdo></b><th id='8ksa3'></th></span></q></dt></tr></i><div class="fflflzr" id='8ksa3'><tfoot id='8ksa3'></tfoot><dl id='8ksa3'><fieldset id='8ksa3'></fieldset></dl></div>

                本文介紹了Google maps JS API v3:使用 containsLocation() 獲取圓圈中的標記不起作用 - 為什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試按照推薦使用 google.maps.geometry.poly.containsLocation 來獲取給定半徑 (google.maps.Circle) 內的所有標記 這里,但我明白了一個錯誤:TypeError: e is undefined.

                I'm trying to get all markers within a given radius (google.maps.Circle) by using google.maps.geometry.poly.containsLocation as recommended here, but I get an error: TypeError: e is undefined.

                片段:

                // ...
                if (google.maps.geometry.poly.containsLocation(randomMarkers[i].marker.getPosition(), searchArea)) {
                    console.log('=> is in searchArea');
                } else {
                    console.log('=> is NOT in searchArea');
                }
                // ...
                

                完整代碼:

                <!DOCTYPE html>
                <html>
                <head>
                <title>Simple Map</title>
                <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
                <meta charset="utf-8">
                <style>
                  html, body, #map-canvas {
                    height: 100%;
                    margin: 0px;
                    padding: 0px
                  }
                </style>
                <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
                <script>
                var map,
                    searchArea,
                    searchAreaMarker,
                    searchAreaRadius = 1000, // metres
                    startLat = 40.782827,
                    startLng = -73.966167       
                ;
                
                function init() {   
                    var startLatLng = new google.maps.LatLng(startLat, startLng);
                
                    map = new google.maps.Map(document.getElementById('map-canvas'), {
                        center: startLatLng,
                        zoom: 12
                    });
                
                    searchArea = new google.maps.Circle({
                        strokeColor: '#FF0000',
                        strokeOpacity: 0.5,
                        strokeWeight: 2,
                        fillColor: '#FF0000',
                        fillOpacity: 0.2,
                        map: map,
                        center: startLatLng,
                        radius: searchAreaRadius
                    });
                
                    searchAreaMarker = new google.maps.Marker({
                        position: startLatLng,
                        map: map,
                        draggable: true,
                        animation: google.maps.Animation.DROP,
                        title: 'searchAreaMarker'
                    });
                
                    var randomMarkers = [
                        { title: 'Marker 1', latLng: new google.maps.LatLng(40.770088, -73.971146) },
                        { title: 'Marker 2', latLng: new google.maps.LatLng(40.782048, -73.972691) },
                        { title: 'Marker 3', latLng: new google.maps.LatLng(40.769048, -73.987797) },
                        { title: 'Marker 4', latLng: new google.maps.LatLng(40.773858, -73.956211) },
                        { title: 'Marker 5', latLng: new google.maps.LatLng(40.800372, -73.952091) },
                        { title: 'Marker 6', latLng: new google.maps.LatLng(40.804661, -73.939388) }            
                    ];
                
                    for (var i = 0; i < randomMarkers.length; i++) {
                        randomMarkers[i].marker = new google.maps.Marker({
                            position: randomMarkers[i].latLng,
                            map: map,
                            title: randomMarkers[i].title
                        });
                    }
                
                    google.maps.event.addListener(searchAreaMarker, 'dragend', function(e) {
                        startLatLng = e.latLng;
                
                        searchArea.setOptions({
                            center: startLatLng
                        });
                
                        map.panTo(searchAreaMarker.getPosition());
                
                        // find markers in area
                        for (var i = 0; i < randomMarkers.length; i++) {
                            console.log('Marker: ' + randomMarkers[i].marker.title + ', position: ' + randomMarkers[i].marker.getPosition()); 
                
                            // ---------- Here comes the error: 
                            // TypeError: e is undefined
                            if (google.maps.geometry.poly.containsLocation(randomMarkers[i].marker.getPosition(), searchArea)) {
                                console.log('=> is in searchArea');
                            } else {
                                console.log('=> is NOT in searchArea');
                            }
                        }
                    });
                }
                
                google.maps.event.addDomListener(window, 'load', init);
                </script>
                


                推薦答案

                containsLocation 是 google.maps.Polygon 上的一種方法對象 不是 google.maps.Circle 對象

                要確定標記是否在圓圈內,請使用 google.maps.geometry.球形.computeDistanceBetween

                To determine if a marker is within a circle use google.maps.geometry.spherical.computeDistanceBetween

                if (google.maps.geometry.spherical.computeDistanceBetween(randomMarkers[i].marker.getPosition(), searchArea.getCenter()) <= searchArea.getRadius()) {
                    console.log('=> is in searchArea');
                } else {
                    console.log('=> is NOT in searchArea');
                }
                

                工作小提琴

                工作代碼片段:

                var map,
                  searchArea,
                  searchAreaMarker,
                  searchAreaRadius = 1000, // metres
                  startLat = 40.782827,
                  startLng = -73.966167;
                
                function init() {
                  var startLatLng = new google.maps.LatLng(startLat, startLng);
                
                  map = new google.maps.Map(document.getElementById('map-canvas'), {
                    center: startLatLng,
                    zoom: 12
                  });
                
                  searchArea = new google.maps.Circle({
                    strokeColor: '#FF0000',
                    strokeOpacity: 0.5,
                    strokeWeight: 2,
                    fillColor: '#FF0000',
                    fillOpacity: 0.2,
                    map: map,
                    center: startLatLng,
                    radius: searchAreaRadius
                  });
                
                  searchAreaMarker = new google.maps.Marker({
                    position: startLatLng,
                    map: map,
                    draggable: true,
                    animation: google.maps.Animation.DROP,
                    title: 'searchAreaMarker'
                  });
                
                  var randomMarkers = [{
                    title: 'Marker 1',
                    latLng: new google.maps.LatLng(40.770088, -73.971146)
                  }, {
                    title: 'Marker 2',
                    latLng: new google.maps.LatLng(40.782048, -73.972691)
                  }, {
                    title: 'Marker 3',
                    latLng: new google.maps.LatLng(40.769048, -73.987797)
                  }, {
                    title: 'Marker 4',
                    latLng: new google.maps.LatLng(40.773858, -73.956211)
                  }, {
                    title: 'Marker 5',
                    latLng: new google.maps.LatLng(40.800372, -73.952091)
                  }, {
                    title: 'Marker 6',
                    latLng: new google.maps.LatLng(40.804661, -73.939388)
                  }];
                
                  for (var i = 0; i < randomMarkers.length; i++) {
                    randomMarkers[i].marker = new google.maps.Marker({
                      position: randomMarkers[i].latLng,
                      map: map,
                      title: randomMarkers[i].title
                    });
                  }
                
                  google.maps.event.addListener(searchAreaMarker, 'dragend', function(e) {
                    startLatLng = e.latLng;
                
                    searchArea.setOptions({
                      center: startLatLng
                    });
                
                    map.panTo(searchAreaMarker.getPosition());
                    findMarkersInArea();
                  });
                  var iwArray = [];
                  function findMarkersInArea() {
                    // close open infowindows
                    for (var i=0; i<iwArray.length; i++) {
                      iwArray[i].close();
                    }
                    iwArray = [];
                    // find markers in area
                    for (var i = 0; i < randomMarkers.length; i++) {
                      console.log('Marker: ' + randomMarkers[i].marker.title + ', position: ' + randomMarkers[i].marker.getPosition());
                      console.log("marker["+i+"] posn="+randomMarkers[i].marker.getPosition().toUrlValue(6));
                      if (google.maps.geometry.spherical.computeDistanceBetween(randomMarkers[i].marker.getPosition(), searchArea.getCenter()) <= searchArea.getRadius()) {
                        console.log('=> is in searchArea');
                        var iw = new google.maps.InfoWindow();
                        iw.setContent("is in searchArea");
                        iw.open(map, randomMarkers[i].marker);
                        iwArray.push(iw);
                      } else {
                        console.log('=> is NOT in searchArea');
                        var iw = new google.maps.InfoWindow();
                        iw.setContent("outside searchArea");
                        iw.open(map, randomMarkers[i].marker);
                        iwArray.push(iw);
                      }
                    }
                  }
                  // initial config
                  findMarkersInArea();
                }
                
                google.maps.event.addDomListener(window, 'load', init);

                html,
                body,
                #map-canvas {
                  height: 100%;
                  width: 100%;
                  margin: 0px;
                  padding: 0px
                }

                <script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
                <div id="map-canvas" style="border: 2px solid #3872ac;"></div>

                這篇關于Google maps JS API v3:使用 containsLocation() 獲取圓圈中的標記不起作用 - 為什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Use IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
                anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 項目中不起作用)
                Ionic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用異步數據更新 Observable)
                Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
                In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何創建使用 Ionic 組件的自定義指令?)
                Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(將 ViewChild 用于動態元素 - Angular 2 amp;離子2)
              • <legend id='SPZvJ'><style id='SPZvJ'><dir id='SPZvJ'><q id='SPZvJ'></q></dir></style></legend>
                <i id='SPZvJ'><tr id='SPZvJ'><dt id='SPZvJ'><q id='SPZvJ'><span id='SPZvJ'><b id='SPZvJ'><form id='SPZvJ'><ins id='SPZvJ'></ins><ul id='SPZvJ'></ul><sub id='SPZvJ'></sub></form><legend id='SPZvJ'></legend><bdo id='SPZvJ'><pre id='SPZvJ'><center id='SPZvJ'></center></pre></bdo></b><th id='SPZvJ'></th></span></q></dt></tr></i><div class="jjr57rf" id='SPZvJ'><tfoot id='SPZvJ'></tfoot><dl id='SPZvJ'><fieldset id='SPZvJ'></fieldset></dl></div>
                <tfoot id='SPZvJ'></tfoot>
                  <bdo id='SPZvJ'></bdo><ul id='SPZvJ'></ul>
                    <tbody id='SPZvJ'></tbody>

                  <small id='SPZvJ'></small><noframes id='SPZvJ'>

                        • 主站蜘蛛池模板: 模温机-油温机-电加热导热油炉-工业冷水机「欧诺智能」 | 高压无油空压机_无油水润滑空压机_水润滑无油螺杆空压机_无油空压机厂家-科普柯超滤(广东)节能科技有限公司 | 六维力传感器_三维力传感器_二维力传感器-南京神源生智能科技有限公司 | 步入式高低温测试箱|海向仪器| 骨密度仪-骨密度测定仪-超声骨密度仪-骨龄测定仪-天津开发区圣鸿医疗器械有限公司 | 光纤测温-荧光光纤测温系统-福州华光天锐光电科技有限公司 | HDPE储罐_厂家-山东九州阿丽贝防腐设备 | 污水处理设备维修_污水处理工程改造_机械格栅_过滤设备_气浮设备_刮吸泥机_污泥浓缩罐_污水处理设备_污水处理工程-北京龙泉新禹科技有限公司 | 骨密度仪-骨密度测定仪-超声骨密度仪-骨龄测定仪-天津开发区圣鸿医疗器械有限公司 | 龙门加工中心-数控龙门加工中心厂家价格-山东海特数控机床有限公司_龙门加工中心-数控龙门加工中心厂家价格-山东海特数控机床有限公司 | 大_小鼠elisa试剂盒-植物_人Elisa试剂盒-PCR荧光定量试剂盒-上海一研生物科技有限公司 | 派财经_聚焦数字经济内容服务平台 | 西安展台设计搭建_西安活动策划公司_西安会议会场布置_西安展厅设计西安旭阳展览展示 | 篷房[仓储-婚庆-展览-活动]生产厂家-江苏正德装配式帐篷有限公司 | KBX-220倾斜开关|KBW-220P/L跑偏开关|拉绳开关|DHJY-I隔爆打滑开关|溜槽堵塞开关|欠速开关|声光报警器-山东卓信有限公司 | 高中学习网-高考生信息学习必备平台 | 奥因-光触媒除甲醛公司-除甲醛加盟公司十大品牌 | 全自动变压器变比组别测试仪-手持式直流电阻测试仪-上海来扬电气 | 多物理场仿真软件_电磁仿真软件_EDA多物理场仿真软件 - 裕兴木兰 | 建筑资质代办-建筑资质转让找上海国信启航 | 郑州水质检测中心_井水检测_河南废气检测_河南中环嘉创检测 | 蚂蚁分类信息系统 - PHP同城分类信息系统 - MayiCMS | 缓蚀除垢剂_循环水阻垢剂_反渗透锅炉阻垢剂_有机硫化物-郑州威大水处理材料有限公司 | 撕碎机,撕破机,双轴破碎机-大件垃圾破碎机厂家 | 伊卡洛斯软装首页-电动窗帘,别墅窗帘,定制窗帘,江浙沪1000+别墅窗帘案例 | 鼓风干燥箱_真空烘箱_高温干燥箱_恒温培养箱-上海笃特科学仪器 | 匀胶机旋涂仪-声扫显微镜-工业水浸超声-安赛斯(北京)科技有限公司 | 电地暖-电采暖-发热膜-石墨烯电热膜品牌加盟-暖季地暖厂家 | 北京四合院出租,北京四合院出售,北京平房买卖 - 顺益兴四合院 | 陕西华春网络科技股份有限公司 | 电缆桥架生产厂家_槽式/梯式_热镀锌线槽_广东东莞雷正电气 | 阁楼货架_阁楼平台_仓库仓储设备_重型货架_广州金铁牛货架厂 | 120kv/2mA直流高压发生器-60kv/2mA-30kva/50kv工频耐压试验装置-旭明电工 | 客服外包专业服务商_客服外包中心_网萌科技 | 蜘蛛车-登高车-高空作业平台-高空作业车-曲臂剪叉式升降机租赁-重庆海克斯公司 | 纯化水设备-EDI-制药-实验室-二级反渗透-高纯水|超纯水设备 | 正压送风机-多叶送风口-板式排烟口-德州志诺通风设备 | 深圳货架厂家_金丽声精品货架_广东金丽声展示设备有限公司官网 | 压装机-卧式轴承轮轴数控伺服压装机厂家[铭泽机械] | 电动葫芦|防爆钢丝绳电动葫芦|手拉葫芦-保定大力起重葫芦有限公司 | 北京办公室装修,办公室设计,写字楼装修-北京金视觉装饰工程公司 北京成考网-北京成人高考网 |