<?php
$lats = array('45.536121999999999','45.535474999999998','45.543616999999998', '45.539473999999998', '45.540157000000001', '45.540672999999998', '45.541322999999998', '45.543159000000003', '45.543792000000003', '45.544383000000003', '45.544913000000001', '45.546010000000003', '45.546326999999998', '45.547044000000000', '45.547294999999998', '45.548855000000003', '45.547285000000002', '45.548077999999997', '45.536045999999999', '45.536721999999997', '45.537255999999999', '45.537205000000000', '45.537900999999998', '45.538570000000000', '45.539793000000003', '45.540351999999999', '45.541108999999999', '45.541524000000003', '45.542295000000003', '45.542800000000000', '45.544369000000003', '45.544713999999999', '45.537736000000002', '45.538330999999999', '45.538930000000001', '45.539527999999997', '45.539994999999998', '45.541469999999997', '45.542006000000001', '45.542684000000001', '45.543751999999998', '45.538646000000000', '45.496099999999998', '45.495916999999999', '45.495392000000002', '45.498137999999997', '45.498694999999998', '45.500134000000003', '45.499898999999999', '45.500698999999997', '45.501230999999997', '45.504922999999998', '45.505772999999998', '45.510435999999999', '45.510314000000001', '45.512287000000001', '45.512025000000001', '45.515154000000003', '45.499257000000000', '45.497490999999997', '45.504133000000003', '45.503286000000003', '45.508197000000003', '45.505267000000003', '45.499701999999999', '45.498911999999997', '45.535254999999999', '45.533490000000000', '45.539659000000000', '45.537733000000003', '45.538139000000001', '45.534306999999998', '45.530244000000003', '45.526229000000001', '45.526054000000002', '45.509990999999999', '45.511139000000000', '45.513714999999998', '45.513131999999999', '45.517851999999998', '45.516260000000003', '45.518608000000000', '45.520389999999999', '45.522537999999997', '45.519264000000000', '45.519933999999999', '45.514927000000000', '45.514234999999999', '45.514875000000004', '45.514639000000003', '45.515490999999997', '45.513106000000001', '45.514505999999997', '45.511986999999998', '45.515870000000000', '45.515982999999999', '45.510433999999997', '45.518861000000001', '45.521203000000000', '45.522336000000003', '45.521394000000001', '45.524385000000002', '45.526617999999999', '45.505906000000003', '45.506065999999997', '45.503363000000000', '45.500900000000001', '45.501855999999997', '45.500093999999997', '45.498778999999999', '45.495663000000000', '45.496893999999998', '45.531458000000001', '45.504437000000003', '45.530993000000002', '45.492927999999999', '45.490274999999997', '45.488028999999997', '45.489448000000003', '45.491256999999997', '45.494041000000003', '45.490295000000003', '45.491008999999998', '45.495116000000003', '45.493783999999998', '45.491613000000001', '45.491571999999998', '45.495998000000000', '45.496440999999997', '45.497324999999996', '45.499730000000000', '45.502639000000002', '45.500019000000002', '45.494211999999997', '45.492247999999996', '45.502237000000001', '45.504638999999997', '45.506087999999998', '45.508831000000001', '45.508705999999997', '45.523803000000001', '45.524312000000002', '45.529536999999998', '45.485295000000001', '45.502597999999999', '45.505755000000001', '45.502223000000001', '45.473824999999998', '45.471665999999999', '45.463231000000000', '45.469925000000003', '45.470300000000002', '45.471170000000001', '45.471899999999998', '45.473280000000003', '45.474029999999999', '45.474330000000002', '45.475130000000000', '45.475580000000001', '45.476239999999997', '45.494841000000001', '45.496200999999999', '45.496217000000001', '45.503965999999998', '45.484879999999997', '45.484409999999997', '45.482765000000001', '45.456088000000001', '45.455939999999998', '45.462446000000000', '45.464910000000003', '45.465978999999997', '45.466548000000003', '45.467320000000001', '45.467652000000001', '45.468179999999997', '45.468629999999997', '45.469380000000001', '45.469881999999998', '45.470440000000004', '45.470730000000003', '45.471280000000000', '45.454293000000000', '45.454611000000000', '45.466839999999998', '45.467230000000001', '45.466079999999998', '45.493879999999997', '45.491900000000001', '45.491269000000003', '45.491038000000003', '45.490471999999997', '45.489745999999997', '45.489015999999999', '45.494736000000003', '45.495649000000000', '45.497539000000003', '45.496806999999997', '45.497019000000002', '45.497230999999999', '45.497580999999997', '45.502499999999998', '45.487057000000000', '45.491303000000002', '45.466630000000002', '45.467280000000002', '45.468541999999999', '45.467891000000002', '45.459724999999999', '45.469155999999998', '45.462600000000002', '45.465981999999997', '45.466470999999999', '45.467419999999997', '45.467911999999998', '45.468397000000003', '45.468910000000001', '45.469957999999998', '45.473728999999999', '45.474848999999999', '45.475312000000002', '45.475808999999998', '45.476424000000002', '45.476332999999997', '45.477260000000001', '45.478358000000000', '45.478766000000000', '45.489259926499898', '45.487082661000002', '45.485231018699899', '45.480492742700001', '45.479614055200003', '45.481847051099898', '45.481349426199898', '45.490368149100000', '45.487618998400002', '45.486257810799898', '45.487725992999898', '45.477517996600000', '45.488860812699897', '45.478642970899898', '45.478848474300001', '45.480386915499899', '45.482290896000002', '45.483903703099898');
$longs = array('-73.622311999999994','-73.622658000000001','-73.628411000000000', '-73.630831000000001', '-73.630832999999996', '-73.630139000000000', '-73.630131000000006', '-73.628755999999996', '-73.628833000000000', '-73.628450000000001', '-73.627923999999993', '-73.626909999999995', '-73.626215000000002', '-73.626172999999994', '-73.625365000000002', '-73.616630000000001', '-73.618470000000002', '-73.619759000000002', '-73.619114999999994', '-73.618925000000004', '-73.618267000000003', '-73.618533999999997', '-73.618314999999996', '-73.617733999999999', '-73.617149999999995', '-73.616797000000005', '-73.615846000000005', '-73.615195999999997', '-73.616761999999994', '-73.618015000000000', '-73.621088000000000', '-73.621683000000004', '-73.624606999999997', '-73.624684000000002', '-73.623941000000002', '-73.623895000000005', '-73.623424999999997', '-73.622939000000002', '-73.622546999999997', '-73.622449000000003', '-73.621638000000004', '-73.627744000000007', '-73.580546999999996', '-73.577285000000003', '-73.573834000000005', '-73.577736000000002', '-73.574477999999999', '-73.575322999999997', '-73.572766999999999', '-73.572066000000007', '-73.571453000000005', '-73.571951999999996', '-73.570516999999995', '-73.568479999999994', '-73.563517000000004', '-73.562758000000002', '-73.559680999999998', '-73.563478000000003', '-73.571735000000004', '-73.565807000000007', '-73.574211000000005', '-73.560231000000002', '-73.560047999999995', '-73.557323999999994', '-73.556472999999997', '-73.566852999999995', '-73.554989000000006', '-73.551989000000006', '-73.559145000000001', '-73.549623999999994', '-73.556667000000004', '-73.559797000000003', '-73.557875999999993', '-73.552970000000002', '-73.548970999999995', '-73.557158999999999', '-73.566633999999993', '-73.560293999999999', '-73.556504000000004', '-73.556467999999995', '-73.560554999999994', '-73.561152000000007', '-73.563338000000002', '-73.565347000000003', '-73.560728999999995', '-73.559747999999999', '-73.550195000000002', '-73.552933999999993', '-73.554372999999998', '-73.559455999999997', '-73.561605000000000', '-73.566102999999998', '-73.568657000000002', '-73.568023999999994', '-73.567832999999993', '-73.565511999999998', '-73.553274000000002', '-73.552542000000003', '-73.557794000000001', '-73.560236000000003', '-73.559820999999999', '-73.560676999999998', '-73.558999999999997', '-73.558216999999999', '-73.560891999999996', '-73.562029999999993', '-73.557492999999994', '-73.555216000000001', '-73.553729000000004', '-73.554452999999995', '-73.553921000000003', '-73.555269999999993', '-73.557158000000001', '-73.561406000000005', '-73.559594000000004', '-73.580686999999998', '-73.585635999999994', '-73.580967000000001', '-73.580434999999994', '-73.580681999999996', '-73.584101000000004', '-73.586331999999999', '-73.582830999999999', '-73.581562000000005', '-73.579065000000000', '-73.576620000000005', '-73.569922000000005', '-73.570984999999993', '-73.584438000000006', '-73.581273999999993', '-73.583783999999994', '-73.580330000000004', '-73.578496000000001', '-73.569890000000001', '-73.565445999999994', '-73.553909000000004', '-73.555640999999994', '-73.555507000000006', '-73.556020000000004', '-73.552081000000001', '-73.553027000000000', '-73.550883999999996', '-73.547949000000003', '-73.627938000000000', '-73.618200000000002', '-73.629489000000007', '-73.634686000000002', '-73.615448000000001', '-73.613866999999999', '-73.646353000000005', '-73.628181999999995', '-73.627409999999998', '-73.626999999999995', '-73.625950000000003', '-73.624709999999993', '-73.624369999999999', '-73.623810000000006', '-73.623490000000004', '-73.622709999999998', '-73.622479999999996', '-73.618977000000001', '-73.619560000000007', '-73.621578000000000', '-73.618104000000002', '-73.628420000000006', '-73.628860000000003', '-73.630121000000003', '-73.639146999999994', '-73.640753000000004', '-73.625352000000007', '-73.626630000000006', '-73.624634000000000', '-73.623253000000005', '-73.622309999999999', '-73.621374000000003', '-73.620699999999999', '-73.619450000000001', '-73.618369999999999', '-73.617131000000001', '-73.616370000000003', '-73.615279999999998', '-73.614720000000005', '-73.639740000000003', '-73.641698000000005', '-73.639279999999999', '-73.638549999999995', '-73.639439999999993', '-73.636420000000001', '-73.631829999999994', '-73.630905999999996', '-73.629981999999998', '-73.629017000000005', '-73.627384000000006', '-73.625770000000003', '-73.638677000000001', '-73.640590000000003', '-73.644257999999994', '-73.620991000000004', '-73.623307999999994', '-73.624283000000005', '-73.625387000000003', '-73.635701999999995', '-73.626531999999997', '-73.622307000000006', '-73.630790000000005', '-73.630364000000000', '-73.629243000000002', '-73.629784000000001', '-73.644689999999997', '-73.628586999999996', '-73.630690000000001', '-73.613776000000001', '-73.613156000000004', '-73.611710000000002', '-73.611009999999993', '-73.610230000000001', '-73.609430000000003', '-73.608221999999998', '-73.609746000000001', '-73.608265000000003', '-73.607654999999994', '-73.607020000000006', '-73.606368000000003', '-73.613240000000005', '-73.615333000000007', '-73.617885000000001', '-73.618797999999998', '-73.586864069200004', '-73.589486889900002', '-73.596462514099898', '-73.611285208300004', '-73.596721256999899', '-73.595551318000005', '-73.599859957199897', '-73.588804409999895', '-73.584295568300007', '-73.588119837299899', '-73.591846641999894', '-73.600058932799897', '-73.585217571499896', '-73.602492261999899', '-73.603276873599896', '-73.608488664399900', '-73.606730263000003', '-73.603064949499895');
$meter = 150;
<Style id="style0">
<LineStyle>
<color>ff000000</color>
<width>1</width>
</LineStyle>
<PolyStyle>
<color>7FAAAAAA</color>
<fill>1</fill>
<outline>1</outline>
</PolyStyle>
</Style>';
for($i = 0; $i < count($lats); $i++) {
$lat = $lats[$i];
$long = $longs[$i];
// Get circle coordinates
$coordinatesList = getCirclecoordinates($lat, $long, $meter);
// Output
$kml .= '<Placemark><name>Circle '.$i.'</name><styleUrl>#style0</styleUrl><Polygon><outerBoundaryIs><LinearRing><coordinates>'.$coordinatesList.'</coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark>';
}
$kml .= '</Document></kml>';
function getCirclecoordinates($lat, $long, $meter) {
// convert coordinates to radians
$lat1 = deg2rad($lat);
$long1 = deg2rad($long);
$d_rad = $meter/6378137;
$coordinatesList = "";
// loop through the array and write path linestrings
for($i=0; $i<=360; $i+=3) {
$radial = deg2rad($i);
$lat_rad = asin(sin($lat1)*cos($d_rad) + cos($lat1)*sin($d_rad)*cos($radial));
$dlon_rad = atan2(sin($radial)*sin($d_rad)*cos($lat1), cos($d_rad)-sin($lat1)*sin($lat_rad));
$lon_rad = fmod(($long1+$dlon_rad + M_PI), 2*M_PI) - M_PI;
$coordinatesList .= rad2deg($lon_rad).",".rad2deg($lat_rad).",0 ";
}
return $coordinatesList;
}
$fp = fopen('test.kml', 'w');
fwrite($fp, $kml);
fclose($fp);
?>