Search code examples
javascriptgoogle-mapsgoogle-maps-api-3locationgeo

Detect region based on geo location


I have a json file with lists of regions.

Each region has geo border points like:

id": "4650d7cc-b834-4ed4-a139-40f5037711fc",
"name": "region 1",
"coords": [
    [
        [4.74, 52.431],
        [4.781, 52.426],
        [4.831, 52.42],
        [4.855, 52.417],
        [4.862, 52.422],
        [4.861, 52.425],
        [4.866, 52.428], ...

How can I detect region based on some location using js, C# or any google service?


Solution

  • You can use the containsLocation method from the Google Maps JavaScript API Geometry Library. From the documentation:

    containsLocation(point:LatLng, polygon:Polygon)

    Return Value: boolean

    Computes whether the given point lies inside the specified polygon.