How to indicate that a point is inside the circle or rectangle by geometry library in Google maps v3?

前端 未结 2 1559
予麋鹿
予麋鹿 2021-01-29 12:38

Look at this:

if(google.maps.geometry.poly.containsLocation(new google.maps.LatLng(arrayLatitude[counter1], arrayLongitude[counter1]), polygon))
{
}
2条回答
  •  暖寄归人
    2021-01-29 13:23

    Important notice: If you don't set getSouthWest and getNorth... it always return false: Google Maps v3 map.getBounds().containsLatLng is not a function

    var temp_rectangle = new google.maps.Rectangle({
        bounds: new google.maps.LatLngBounds(
        new google.maps.LatLng(array_shapes_object[counter].getSouthWestLat, array_shapes_object[counter].getSouthWestLng),
        new google.maps.LatLng(array_shapes_object[counter].getNorthEastLat, array_shapes_object[counter].getNorthEastLng))
    });
    
    if(temp_rectangle.getBounds().contains(new google.maps.LatLng(arrayLatitude[counter1], arrayLongitude[counter1])))
    {
        alert("Inside");
    }
    else
    {
        alert("Outside");
    }
    

提交回复
热议问题