Skip to content

Instantly share code, notes, and snippets.

@aaronpk
Created July 8, 2011 02:58
Show Gist options
  • Select an option

  • Save aaronpk/1071024 to your computer and use it in GitHub Desktop.

Select an option

Save aaronpk/1071024 to your computer and use it in GitHub Desktop.
yay trig!
var G = google.maps.geometry.spherical;
var A = placeMarker.getPosition();
var B = event.latLng;
var radians = function(degrees) { return degrees * (Math.PI/180); };
// Compute the angle from A to B
var beta = G.computeHeading(A, B);
// The angle of the second triangle is 45 degrees plus the previous angle
var gamma = 45 + beta;
// The radius of the circle is cos(gamma) * distance from A to B
var x = G.computeDistanceBetween(A, B);
radius = Math.cos(radians(gamma)) * x;
placeMarkerHandle.setPosition(G.computeOffset(A, radius, -45));
for(var i=0; i<2; i++) {
circles[i].circle.setRadius(radius - (i*3));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment