Drawing a sector in API v3

1,098 views
Skip to first unread message

subversionpdx

unread,
Dec 14, 2011, 2:44:30 PM12/14/11
to Google Maps JavaScript API v3
Updated someone else's previous example of this for Google Maps API V3
-

Anyone know if something like this can be filled with a color /
opacity?

function drawSector(lat,lng,r,azimuth,width) {
//Degrees to radians
var d2r = Math.PI / 180;
// Radians to degrees
var r2d = 180 / Math.PI;


var centerPoint = new google.maps.LatLng(lat,lng);
var PRlat = (r/3963) * r2d; // using 3963 miles as earth's
radius
var PRlng = PRlat/Math.cos(lat*d2r);
var PGpoints = [];
PGpoints.push(centerPoint);
with (Math) {
lat1 = lat + (PRlat * cos( d2r * (azimuth - width/2 )));
lon1 = lng + (PRlng * sin( d2r * (azimuth - width/2 )));
PGpoints.push( new google.maps.LatLng(lat1,lon1));
lat2 = lat + (PRlat * cos( d2r * (azimuth + width/2 )));
lon2 = lng + (PRlng * sin( d2r * (azimuth + width/2 )));
var theta = 0;
var gamma = d2r * (azimuth + width/2 );
for (var a = 1; theta < gamma ; a++ ) {
theta = d2r * (azimuth - width/2 +a);
PGlon = lng + (PRlng * sin( theta ));
PGlat = lat + (PRlat * cos( theta ));
PGpoints.push(new
google.maps.LatLng(PGlat,PGlon));
}
PGpoints.push( new google.maps.LatLng(lat2,lon2));
PGpoints.push(centerPoint);
}
var poly = new google.maps.Polyline({map: map, path:
PGpoints, strokeColor: "#00ff00", strokeOpacity: 1.0,
strokeWeight: 2 });
poly.setMap(map);
return poly;
}

Andrew Leach

unread,
Dec 14, 2011, 3:15:00 PM12/14/11
to google-map...@googlegroups.com
On 14 December 2011 19:44, subversionpdx <subver...@gmail.com> wrote:
> Updated someone else's previous example of this for Google Maps API V3
>
> Anyone know if something like this can be filled with a color /
> opacity?
>
>            var poly = new google.maps.Polyline({map: map, path:
> PGpoints, strokeColor: "#00ff00", strokeOpacity: 1.0,
>                strokeWeight: 2 });

If you use Polygon instead of Polyline you get additional options.

http://code.google.com/apis/maps/documentation/javascript/reference.html#PolygonOptions

subversionpdx

unread,
Dec 14, 2011, 3:17:54 PM12/14/11
to Google Maps JavaScript API v3
Thank you, that worked perfectly :)

Joe

On Dec 14, 12:15 pm, Andrew Leach <andrew.leac...@gmail.com> wrote:


> On 14 December 2011 19:44, subversionpdx <subversion...@gmail.com> wrote:
>
> > Updated someone else's previous example of this for Google Maps API V3
>
> > Anyone know if something like this can be filled with a color /
> > opacity?
>
> >            var poly = new google.maps.Polyline({map: map, path:
> > PGpoints, strokeColor: "#00ff00", strokeOpacity: 1.0,
> >                strokeWeight: 2 });
>
> If you use Polygon instead of Polyline you get additional options.
>

> http://code.google.com/apis/maps/documentation/javascript/reference.h...

atango pascall

unread,
Oct 26, 2017, 6:43:29 PM10/26/17
to Google Maps JavaScript API v3
It is okay. i can draw several sectors now. but please how can i save the sectors in a database such as mysql? thanks
Reply all
Reply to author
Forward
0 new messages