Sijan Bhattarai
Sijan Bhattarai

Reputation: 650

Knowing if a user picked point is inside or outside a pre-specified area from google map api

In my application the user chooses two points as start and end. Is there any way to customize the google map api so as to know if any of the two places lies inside or outside a pre-specified Ring-road.

Upvotes: 0

Views: 34

Answers (1)

Denysole
Denysole

Reputation: 4051

You can use containsLocation() method from Google Maps API, to detect if point located inside the polygon.

Initialize polygon :

var ringRoad= [
    {lat: 25.774, lng: -80.19},
    {lat: 18.466, lng: -66.118},
    {lat: 32.321, lng: -64.757}
];

var bermudaTriangle = new google.maps.Polygon({paths: triangleCoords});

Then call:

google.maps.geometry.poly.containsLocation(latLng, bermudaTriangle)

You'll get true if point (latLng) located inside the polygon, and false otherwise. More details you can get from this and this documentation articles.

Upvotes: 2

Related Questions