久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" 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'>

                        • 主站蜘蛛池模板: 国产91视频一区二区 | 久久伊人免费视频 | 亚洲欧美一区在线 | 日韩欧美专区 | 欧美性精品 | 成年人黄色一级毛片 | 一级黄色绿像片 | av色噜噜 | 日韩成人一区 | 国产一区亚洲二区三区 | 色综合天天综合网国产成人网 | 欧美一区免费 | 九九热精品免费 | 国产区精品在线观看 | 乱码av午夜噜噜噜噜动漫 | 欧洲视频一区二区 | 特一级毛片 | 免费观看色 | 久久久久久综合 | 成人在线观看免费视频 | 亚洲天堂中文字幕 | 中文字幕日韩欧美一区二区三区 | 最新国产精品视频 | 国产亚洲一区二区三区在线观看 | 91人人视频在线观看 | 国产精品久久久久久久久久了 | 国产精品久久久久久久久久久久久 | 亚洲一区 | 视频在线一区二区 | 一级黄片一级毛片 | 亚洲精品久久久一区二区三区 | 一区二区视频 | 婷婷成人在线 | www国产成人免费观看视频,深夜成人网 | 一区二区三区在线观看视频 | 精品国产一区二区三区久久狼黑人 | 在线观看成人 | 国产麻豆乱码精品一区二区三区 | 热99在线| 亚洲一区二区三区国产 | 欧美三区在线观看 |