Reputation: 63619
I am using Google Maps V3 API to create a polyline with 2 points. Now that I have created the polyline, I want to shorten it.
Problem: I need the polyline to extend from the start point to the midpoint between the start and end points. How can I achieve this?
The closest function that I can find is computeDistanceBetween()
function for finding the distance between 2 LatLng points.
Javascript Code
start_latlng = new google.maps.LatLng(42.354183,-71.065063);
end_latlng = new google.maps.LatLng(42.354183,-71.069063);
start_marker = new google.maps.Marker({
position: start_latlng,
map: map
});
end_marker = new google.maps.Marker({
position: end_latlng,
map: map
});
path = [];
path.push(start_latlng);
path.push(end_latlng);
var polyline = new google.maps.Polyline ({
strokeColor: "#970E04",
strokeOpacity: 1.0,
strokeWeight: 2,
path: path,
map: map
})
Upvotes: 2
Views: 1008
Reputation: 21630
This is a great resource for mapping functions:
http://www.movable-type.co.uk/scripts/latlong.html
There is an example for calculating a midpoint.
Upvotes: 2