1

Given that you have this circle defined on your map, how would you get the LatLong of the point that intersects at a given angle?

var degrees = 90;
var center = {lat: 34.052235, lng: -118.243683};
var circle = new google.maps.Circle({
    center: center,
    radius: 500000
});

var pointOnCircle = ?

Map

  • 1
    Uhm, you have already the coordinate and the radius of the circle? – KarelG Oct 02 '17 at 12:59
  • @KarelG I don't think you understand what I'm asking. I want to be able to input any given angle to get a point on the circle. – Merilynn Bandy Oct 02 '17 at 13:02
  • 1
    Use some trigonometry to find the distances. `rcos(θ)` and `rsin(θ)`. Then add to the current coordinates. – Andrew Li Oct 02 '17 at 13:05
  • @AndrewLi Provide some code for your answer? I have no idea how to do this. – Merilynn Bandy Oct 02 '17 at 13:17
  • duplicate of duplicate? https://stackoverflow.com/questions/839899/how-do-i-calculate-a-point-on-a-circle-s-circumference – Neoares Oct 02 '17 at 13:21
  • @Neoares This isn't a duplicate. I'm asking specifically how to find a **latitude** and **longitude** on Google Maps. This requires not only code to solve but knowledge of how to convert from meters to LatLong. – Merilynn Bandy Oct 02 '17 at 13:24
  • @whimzee you can not convert from meters to LatLong an easy way, since the Earth is not a perfect sphere... so if there is a solution, it should be given by google maps (which I don't know) – Neoares Oct 02 '17 at 13:34

1 Answers1

1

You can use the geometry library computeOffset method:

  var pointOnCircle = google.maps.geometry.spherical.computeOffset(circle.getCenter(), circle.getRadius(), degrees);

proof of concept fiddle

screen shot of result

code snippet:

function initialize() {
  var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(37.4419, -122.1419),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });
  var degrees = 90;
  var center = {
    lat: 34.052235,
    lng: -118.243683
  };
  var circle = new google.maps.Circle({
    center: center,
    radius: 500000,
    map: map
  });
  map.fitBounds(circle.getBounds());
  var pointOnCircle = google.maps.geometry.spherical.computeOffset(circle.getCenter(), circle.getRadius(), degrees);
  var marker = new google.maps.Marker({
    map: map,
    position: pointOnCircle
  });
  var polyline = new google.maps.Polyline({
    map: map,
    path: [circle.getCenter(), pointOnCircle]
  })
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry"></script>
<div id="map_canvas"></div>
geocodezip
  • 158,664
  • 13
  • 220
  • 245