【发布时间】:2019-04-24 14:16:06
【问题描述】:
我有一个点(纬度,经度)例如:25,-80,我正在寻找一种方法在 c# 中检查该点是否在特定的多边形中。
我做了一些研究,发现 Google 地图几何库中包含的 containsLocation 函数正是我需要的,但它不适用于 c#。这是一个在 JS 中使用该方法的示例:
// 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 triangleCoords = [
{lat: 25.774, lng: -80.19},
{lat: 18.466, lng: -66.118},
{lat: 32.321, lng: -64.757}
];
var coords = new google.maps.LatLng(25.774, -80.19);
var bermudaTriangle = new google.maps.Polygon({paths: triangleCoords});
var result = google.maps.geometry.poly.containsLocation(coords, bermudaTriangle);
alert('The location exist in polygon: '+result);
}
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&libraries=geometry&callback=initMap"
async defer></script>
我找到了一个用于 gmaps google maps API for C# 的 c# 库,但它不支持函数 containsLocation 有没有办法在 c# 中完成上述要求?
【问题讨论】:
标签: javascript c# google-maps google-poly