In my google maps program I have simple KML parser which retrieve only coordinates and create polylines on map for them, additionally in every point create markers that are used later to edit the line. With longer routes map hangs from the excess of markers. I got the idea, maybe you can create markers only if the curve exceeds 10 degrees? Now I have if which is screened only every second point but this is weak idea.
Illustrative unpacking an array:
for (var i=0;i<coords.length;i++) {
if(i!=0&&i!=coords.length-1){
var prevpt = new google.maps.LatLng(coords[i-1].lat, coords[i-1].lng);
var pivot = new google.maps.LatLng(coords[i].lat, coords[i].lng);
var nextpt = new google.maps.LatLng(coords[i+1].lat, coords[i+1].lng);
var marker = createMarker(pivot);
polyMarkers.push(marker);
var path = polyLine.getPath();
path.push(pivot);
}
}
How to calculate that the next exceeds 10 degrees?
Maybe you have some other idea of how it can be optimized?
It seems that you need polyline simplification – Douglas-Peucker algorithm. Here is another description with implementation