使用REST API在PHP中查找latlong位置是否属于Google Maps多边形


Finding whether latlong location belongs to a Google Maps polygon in PHP with REST API

查找latlong位置是否属于PHP中的Google maps多边形。

我的问题是我在数据库中有一组latlong,他们正在谷歌地图上形成一个多边形,我想测试我的客户端/一些资源提供的latlong是否属于该多边形内,我不使用这个解决方案,因为它是交互式解决方案,这意味着我们点击地图然后它会给出绿色或红色圆圈的反馈

                        <script>
                  // This example requires the Geometry library. Include the libraries=geometry
                  // parameter when you first load the API. For example:
                  // <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=geometry">
                  function initMap() {

                    // var map = new google.maps.Map(document.getElementById('map'), {
                    //   center: {lat: 24.886, lng: -70.269},
                    //   zoom: 5,
                    // });
            console.log('step1');
            /*
                    var triangleCoords = [
                      {lat: 25.774, lng: -80.19},
                      {lat: 18.466, lng: -66.118},
                      {lat: 32.321, lng: -64.757}
                    ];
            */
            var triangleCoords = "[{"lat":-34.875334116012,"lng":138.52427244186},{"lat":-34.95528700453,"lng":138.53869199753},{"lat":-34.958100827485,"lng":138.69730710983},{"lat":-34.880403863759,"lng":138.71653318405}]"; 
            var point = new google.maps.LatLng(-34.933448, 138.595618);

            console.log('step2');
                 var bermudaTriangle = new google.maps.Polygon({paths: triangleCoords});

            console.log('step3');

                      var resultColor =
                          google.maps.geometry.poly.containsLocation(point , bermudaTriangle) ?
                          'red' :
                          'green';
            console.log('step4');
                          console.log(resultColor);


                  }
                </script>

                <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAeAQfn6BM5p8FhFde5yq7fm7V-DHQL0RQ&libraries=geometry&callback=initMap"
                     async defer></script>