With V3, it's pretty easy.
var polygons = [];
And then just skip all your polingons from the database with the following code.
//Add all your coordinates in with new google.maps.LatLng(lat, lng), var coords = [ new google.maps.LatLng(12.5, -8.2), new google.maps.LatLng(12.52, -8.21), etc.... ]; // Construct the polygon polygons.push(new google.maps.Polygon({ paths: coords, other_options: etc.... })); polygons[polygons.length-1].setMap(map); //Your map object
Secondly (out of interest) MySql can store polygons using spatial data types (see Polygon Data Type )
This may help if you need to request data. You are limited to minimal bounding boxes, but I think this data type is better.
To extract the polygon from MySql as lat / lng coordinates, see mysql AsText () function.
eg:
select AsText(my_polygon_column) as blob;
And then pass this through this php function:
function sql_to_coordinates($blob) { $blob = str_replace("))", "", str_replace("POLYGON((", "", $blob)); $coords = explode(",", $blob); $coordinates = array(); foreach($coords as $coord) { $coord_split = explode(" ", $coord); $coordinates[]=array("lat"=>$coord_split[0], "lng"=>$coord_split[1]); } return $coordinates; }
Niall source share