Javascript 谷歌地图3 API-点击功能(来自geojson)并检查它是否包含位置

Javascript 谷歌地图3 API-点击功能(来自geojson)并检查它是否包含位置,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我已在地图上成功加载geojson文件。我可以单击每个多边形来更改笔划并访问其属性。但我想知道,在每个多边形中是否有某些点 我使用google.maps.geometry.poly.containsLocation()来表示普通多边形。是否有一种方法可以从event.feature.getGeometry()提取多边形。。。要在ContainesLocation中使用或使用其他方法来检查此问题 map.data.loadGeoJson('inc-tracts.json'); var featur

我已在地图上成功加载geojson文件。我可以单击每个多边形来更改笔划并访问其属性。但我想知道,在每个多边形中是否有某些点

我使用google.maps.geometry.poly.containsLocation()来表示普通多边形。是否有一种方法可以从event.feature.getGeometry()提取多边形。。。要在ContainesLocation中使用或使用其他方法来检查此问题

map.data.loadGeoJson('inc-tracts.json');
var featureStyle = {
    strokeColor: '#000000',
    strokeOpacity: 0.5,
    strokeWeight: 3,
}
map.data.setStyle(featureStyle);
map.data.addListener('click', function(event) {
    console.log(event.feature.getProperty("CTNAME"));
    // This is where I want to check if point(s) fall within it.
}
好吧,我解决了这个问题

map.data.loadGeoJson('inc-tracts.json');
var featureStyle = {
    strokeColor: '#000000',
    strokeOpacity: 0.5,
    strokeWeight: 3,
}
map.data.setStyle(featureStyle);
map.data.addListener('click', function(event) {
    testPoly = new google.maps.Polygon( { paths:event.feature.getGeometry().getAt(0).getAt(0).getArray() } );
    if ( google.maps.geometry.poly.containsLocation(somePoint, testPoly) ) {
    // This works now, still have to loop through the arrays for the multipolygons
    }
}
奇怪的是,如果我在.containsLocation中使用event.feature.getGeometry().getAt(0)(它返回一个多边形),我会收到错误,因此我必须使用坐标创建一个新的多边形,它才能工作。不确定这是因为我使用的geojson还是其他原因。

A不是一个。该方法包含两个论点:

Methods Return Value Description containsLocation(point:LatLng, polygon:Polygon) boolean Computes whether the given point lies inside the specified polygon.