【问题标题】:Having difficulty in finding the existence of a location inside an area on Google Maps难以在 Google 地图上找到某个区域内的某个位置
【发布时间】:2013-01-17 12:29:07
【问题描述】:

我在 Google 地图上绘制了一个多边形。但我无法验证该区域内是否存在一个点。我怎样才能做到这一点?任何建议将不胜感激。

<!DOCTYPE html>
<html>
<head>
    <title>Polygon</title>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=my_API_key&sensor=false&libraries=geometry"></script>
    <script>
        var centerPoint = new google.maps.LatLng(22.65, 88.45);
        var centerPoint2 = new google.maps.LatLng(28.3, 86.3167);
        var centerPoint3 = new google.maps.LatLng(22.65, 88.45);
        var centerPoint4 = new google.maps.LatLng(20.6333, 84.3167);
        var centerPoint5 = new google.maps.LatLng(24.6333, 85.3167);
        function Initialize() {
            var mapProp = {
                center: centerPoint,
                zoom: 4,
                mapTypeId: google.maps.MapTypeId.HYBRID
            };
            var map = new google.maps.Map(document.getElementById("MyMap"), mapProp);
            var marker = new google.maps.Marker({
                                                  position: centerPoint,
                                                  animation: google.maps.Animation.BOUNCE
                                               });
    var myTrip = [centerPoint2, centerPoint3, centerPoint4];
    var flightPath = new google.maps.Polygon({
                        path: myTrip,
                        strokeColor: "#0000FF",
                        strokeOpacity: 0.2,
                        strokeWeight: 2,
                        fillColor: "#B0F0FF",
                        fillOpacity: 0.4,
                        editable: true
                        });
            marker.setMap(map);
    flightPath.setMap(map);
    var locationExists = new  google.maps.geometry.poly.containsLocation({
                                    point: centerPoint5,
                                    polygon: flightPath
                                });
    document.getElementById("MyData").innerHTML = locationExists;
         }
         google.maps.event.addDomListener(window, 'load', Initialize);
    </script>
</head>
<body>
    <div id="MyMap" style="height: 500px; width: 500px;"></div>
    <div id="MyData" style="height: 500px; width: 500px;"></div>
</body>

containsLocation() 使用正确吗?如果没有,请提出建议。

【问题讨论】:

  • 虽然图像不一样..但想法是。

标签: javascript html google-maps-api-3 dom-events


【解决方案1】:

使用google.maps.geometry.poly.containsLocation

注意:geometry-library默认不加载,必须使用maps-api的libraries-parameter加载

【讨论】:

  • containsLocation(point:LatLng, polygon:Polygon) 我应该在多边形中提供什么:???部分?
  • 您要检测点是否在其中的 google.maps.Polygon-object
  • 请为您的尝试创建一个小提琴,没​​有任何代码就无法提供帮助
  • 哎呀!是的,对不起。我……等一下。
  • 错误:对象不支持属性或方法'lng'
猜你喜欢
  • 2016-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-12
  • 2020-08-15
  • 1970-01-01
  • 1970-01-01
  • 2017-10-21
相关资源
最近更新 更多