Check whether or not a point is in a polygon (Google Maps API)

旧时模样 提交于 2021-02-07 10:57:47

问题


So I have a map here

How can I, using Google Maps API, detect whether or not a given coordinate is within that polygon? Is that possible?

Thanks in advance.


回答1:


Yes it is possible. See this function: http://github.com/tparkin/Google-Maps-Point-in-Polygon




回答2:


Google provides one already

  var bermudaTriangle = new google.maps.Polygon({
    paths: [
      new google.maps.LatLng(25.774, -80.190),
      new google.maps.LatLng(18.466, -66.118),
      new google.maps.LatLng(32.321, -64.757)
    ]
  });

  google.maps.event.addListener(map, 'click', function(event) {
    console.log(google.maps.geometry.poly.containsLocation(event.latLng, bermudaTriangle));
  });

https://developers.google.com/maps/documentation/javascript/geometry#containsLocation



来源:https://stackoverflow.com/questions/3943634/check-whether-or-not-a-point-is-in-a-polygon-google-maps-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!