# How to build a sector on a Google Maps?

The task was to build a sector on the map Google maps (GM). As far as I know, this can only be done using direct. http://maps.forum.nu/ here there are examples of how to build a circle, but it doesn’t work for me. Since the circle is constructed according to the following principle: the coordinates of an arbitrary point on the circle are calculated by the formulas: where r2d and d2r are the translations from radians to degrees and vice versa, respectively. Lat - latitude of the center of the circle. I’ll say right away that this formula is not completely clear to me, but it works and gives the correct coordinates of the point on the circle. After that, from the obtained point we draw 360 lines with a certain step. there is still such an option for constructing a circle, but I did not understand its calculations a little, but everything is done according to the same principle

``` var PGlat = (PGradius/3963)*r2d; // using 3963 miles as earth's radius var PGlng = PGlat/Math.cos(lat*d2r);```

``` var PGsides = 360; var PGstart = (PGsides%2 == 1) ? 2/PGsides : 1/PGsides; PGstart = (0.5 - PGstart) * Math.PI; for (var i=-1; i < PGsides; i++) { var theta = 2*i*Math.PI/PGsides + PGstart; PGx = lng + (PGlng * Math.cos(theta)); PGy = lat + (PGlat * Math.sin(theta)); PGpoints.push(new GPoint(PGx,PGy)); }```

```if (circleUnits == 'KM') { var d = circleRadius/6378.8; // radians } else { //miles var d = circleRadius/3963.189; // radians } var lat1 = (PI/180)* center.lat(); // radians var lng1 = (PI/180)* center.lng(); // radians for (var a = 0 ; a < 361 ; a++ ) { var tc = (PI/180)*a; var y = asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc)); var dlng = atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(y)); var x = ((lng1-dlng+PI) % (2*PI)) - PI ; // MOD function var point = new GLatLng(parseFloat(y*(180/PI)),parseFloat(x*(180/PI))); circlePoints.push(point); bounds.extend(point); } if (d < 1.5678565720686044) { circle = new GPolygon(circlePoints, '#000000', 2, 1, '#000000', 0.25); } else { circle = new GPolygon(circlePoints, '#000000', 2, 1); } map.addOverlay(circle); ```

Let's get back to building the sector.
Input values:
lat, lng - coordinates of the center;
``` PGlat = lat + (r * Math.cos( (azimuth - width/2 ))); PGlon = lng + (r* Math.sin( (azimuth - width/2 ))); PGlat = lat + (r * Math.cos( (azimuth + width/2 ))); PGlon = lng + (r* Math.sin( (azimuth + width/2 )));```