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

前端 未结 2 1554
予麋鹿
予麋鹿 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");
    }
    
    0 讨论(0)
  • 2021-01-29 13:31

    Both Circle and Rectangle have method

    getBounds() LatLngBounds Returns the bounds of this rectangle.

    Try call method getBounds() witch return google.maps.LatLngBounds item. It has method

    contains(latLng:LatLng) boolean Returns true if the given lat/lng is in this bounds.

    something like

    (new google.maps.Circle({center: new google.maps.LatLng(YOUR_LAT, YOUR_LNG),radius: YOUR_RADIUS})).getBounds().contains(google.maps.LatLng(POINT_LAT, POINT_LNG))
    

    Hope it is what you need

    0 讨论(0)
提交回复
热议问题