Reputation: 23
I have a set of GPS locations that I put on a map with mapbox and then draw a line between the points.
Is there a way to draw a smooth/intelligence line that follow the roads? instead of what I got on the drawing?
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Single marker</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.0.0/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.0.0/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
L.mapbox.accessToken = '<TOKEN_HERE>';
var map = L.mapbox.map('map', 'examples.map-i86nkdio')
.setView([40.763656, -73.980603], 15);
L.mapbox.featureLayer({
// this feature is in the GeoJSON format: see geojson.org
// for the full specification
type: 'Feature',
geometry: {
type: 'LineString',
// coordinates here are in longitude, latitude order because
// x, y is the standard for GeoJSON and many formats
coordinates: [
[ -73.979552 , 40.766119 ],
[ -73.982556 , 40.761991 ],
[ -73.980399 , 40.759858 ],
[ -73.978575 , 40.756607 ]
]
},
properties: {
title: 'test',
description: 'Test',
}
}).addTo(map);
</script>
</body>
</html>
Image: http://postimg.org/image/x1syq28o5/
Upvotes: 1
Views: 1663
Reputation: 5128
The line that you've drawn only has the four points you provided. So basically, you need better source data.
Are you trying to do this in a general case or just for this example? The map that you are drawing on is based on OpenStreetMap, so if you could grab that data, you could draw a copy of the road you want on top of the base map.
Upvotes: 1