How to use containsLocation in Google maps geometry library.

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

I am trying to use the containsLocation from the Google geometry library, but can't get it to work...

var point = new google.maps.LatLng(51.331, 3.538); var poly = [  new google.maps.LatLng(51.401818509550615, 3.547626782103622),  new google.maps.LatLng(51.397574277049365, 3.563607598960424),  new google.maps.LatLng(51.398540111384975, 3.567880788749134),  ... // it is a lot bigger ];  if(google.maps.geometry.poly.containsLocation(point, poly) == true) {  alert("yes"); } 

The Javascript console gives an error, but that points to a function in Google's lib. So I assume the problem should lie somewhere in this function.

回答1:

Oke, stupid me

I was wrong using all the coords as an array, I had to use the created polygon object.

var polyOptions = {  ... }  draw = new google.maps.Polygon(polyOptions); draw.setMap(map);  if(google.maps.geometry.poly.containsLocation(point, draw) == true) {  alert("yes"); } 


回答2:

i had the same problem ([object Object]), I could solve that creating the polygon variable like that: draw = new google.maps.Polygon({paths:polyOptions});

Then the problem disappeared.



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