-1

Here is the code I have so far:

function initialize() {
  var mapOptions = {
    center: { lat: 21.9072222, lng: -47.715},
    zoom: 3
  };
  var map = new google.maps.Map(document.getElementById('derby-to-lima'),
      mapOptions);

  var line = new google.maps.Polyline({
    path: [new google.maps.LatLng(53.9834124, -1.5863153), new google.maps.LatLng(-12.0553442, -77.0451853)],
    strokeColor: "#008CBA",
    geodesic: true,
    strokeOpacity: 0.5,
    strokeWeight: 5,
    map: map
  });
}
google.maps.event.addDomListener(window, 'load', initialize);

I want to draw another line on top of the existing one that stops at the point in between the two points, which can be changed by percentage. It's kind of hard to explain, but imagine the first point is the start, and the last is the end. You are given how far a runner currently is by the percentage of the way through they are. Now show how far they are (assuming they ran in a straight line).

Thanks, I've been stuck on this for a while.

ntzm
  • 4,663
  • 2
  • 31
  • 35
  • 2
    [**`google.maps.geometry.spherical.interpolate()`**](https://developers.google.com/maps/documentation/javascript/reference#spherical) – Dr.Molle Dec 23 '14 at 19:17
  • possible duplicate of [latLng from polyLine Percentage](http://stackoverflow.com/questions/19128954/latlng-from-polyline-percentage/19129543#19129543) – geocodezip Dec 23 '14 at 19:40
  • possible duplicate of [Midpoint of route in google maps](http://stackoverflow.com/questions/23176555/midpoint-of-route-in-google-maps/23185777#23185777) – geocodezip Dec 23 '14 at 19:42
  • possible duplicate of [Calculate the geo position at given time](http://stackoverflow.com/questions/25562799/calculate-the-geo-position-at-given-time/25568700#25568700) – geocodezip Dec 23 '14 at 19:45

1 Answers1

1

As suggested by @Dr.Molle load the geometry library and use the method interpolate.

var startPoint =  new google.maps.LatLng(53.9834124, -1.5863153); 
var endPoint = new google.maps.LatLng(-12.0553442, -77.0451853);
var percentage = 0.5; 
var middlePoint = new google.maps.geometry.spherical.interpolate(startPoint, endPoint, percentage); 

FIDDLE

MamaWalter
  • 2,073
  • 1
  • 18
  • 27