I extracted country outline data from somewhere and successfully managed to convert it into an array of lat-lng coordinates that I can feed to Google maps API to draw polyline or polygons.
The problem is that that there are about 1200+ points in that shape. It renders perfectly in Google maps but I need to reduce the number of points from 1200 to less than 100. I don't need a very smooth outline, i just need to throw away the points that I can live without. Any algorithm or an online tool that can help me reduce the number of points is needed.
Google Maps actually has zero route optimization features, meaning you have to do all the calculations manually when you have multiple stops to make.
I was looking for exactly the same thing and found Simplify.js. It does exactly what you want and is incredibly easy to use. You simply pass in your coordinates and it will remove all excess points.
simplify(points, tolerance, highQuality)
The points
argument should contain an array of your coordinates formatted as {x: 123, y: 123}
. (Afterwards you can convert it back to the format you wish.)
The tolerance
should be the precision in decimal degrees. E.g. 0.0001
for 11 meters. Increasing this number will reduce the output size.
Set highQuality
to true
for better results if you don't mind waiting a few milliseconds longer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With