1

I am searching for a possibility to check whether a GPS location is inside a certain custom created area preferably created in Google My Maps from Google Maps.

I have created an area in Google My Maps:

Google My Maps area

Getting the GPS coordinates isn't a big deal, but how can I compare, whether it is inside the selected area? I have read about the possibility to check whether it is within a radius, but not a exact area.

halfer
  • 19,824
  • 17
  • 99
  • 186
THE-E
  • 193
  • 3
  • 4
  • 21

1 Answers1

4

You can use the containsLocation method provided by Maps Javascript API.

Pass the marker and polygon to the function and it will return a message stating whether marker is inside or outside the polygon. You can customize the function as per your need.

function isMarkerInPolygon(marker, polygon){
    var message = google.maps.geometry.poly.containsLocation(marker.latLng, polygon) ?
              'Inside Polygon' :
              'Outside Polygon';
    return message;
}

If you are using it in Android you can use the PolyUtil.containsLocation method from the Google Maps Android API Utility Library. This answer should be helpful : https://stackoverflow.com/a/41203381

Joyson
  • 3,025
  • 1
  • 20
  • 34