I am currently debating whether to use json or kml for storing polygons in a server file. The ultimate goal is to read this file and determine which polygon a specific point falls within. My initial inclination leans towards kml due to its efficiency in rendering with just two lines using the Google Maps Javascript API:
var importedKml = new google.maps.KmlLayer('mykml.kml');
importedKml.setMap(map);
The downside, however, is the absence of a built-in function for checking if a point falls inside all the polygons in a kml file. While I can check if a point resides in a polygon individually using:
google.maps.geometry.poly.containsLocation(latlngPoint, polygon);
it seems that each feature needs to be converted into a google.maps.polygon object beforehand.
As an alternative, I have contemplated reverting back to json as it offers extensive customization options, allowing for easier direct access such as:
//json object polygonFile from server
google.maps.geometry.poly.containsLocation(latlngPoint, polygonFile.polygons[0].polygon);
This method involves creating a custom structure but lacks a straightforward way to render json onto the map unless they are converted into google maps objects first.
Is there a solution to verify if a point lies within a polygon in a kml file without having to convert each feature into google maps objects? If not, converting a json object to google maps objects seems like the more feasible approach.