-1

I'm getting a JSON return like so:

[{"lat":38.660274,"lng":-90.136198},{"lat":38.6613,"lng":-90.13860199999999},{"lat":38.664634,"lng":-90.141853},{"lat":38.664634,"lng":-90.141853},{"lat":38.664305999999996,"lng":-90.142608},{"lat":38.664305999999996,"lng":-90.142608},{"lat":38.65996,"lng":-90.137664},{"lat":38.656954999999996,"lng":-90.135108},{"lat":38.653724,"lng":-90.133544},{"lat":38.650299,"lng":-90.132881},{"lat":38.650299,"lng":-90.132881},{"lat":38.644039,"lng":-90.132278},{"lat":38.642413,"lng":-90.132567},{"lat":38.634983,"lng":-90.139129},{"lat":38.634983,"lng":-90.139129},{"lat":38.633693,"lng":-90.143287},{"lat":38.633693,"lng":-90.143287},{"lat":38.63322,"lng":-90.144256},{"lat":38.632362,"lng":-90.14411799999999}]

How can I use jQuery to convert this into a line string? Or does leaflet have such a function?

  • Welcome to gis.stackexchange! Please note that a good question on this site is expected to show some degree of research on your part, i.e. what you have tried and - if applicable - code so far. For more info, you can check our faq. – underdark Oct 26 '15 at 0:02
1

See the Leaflet polyline documentation:

// create a red polyline from an array of LatLng points
var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);

where latlngs is your JSON result. Here's a quick JS Fiddle example.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.