1

I am working with leafletjs.com and added MAP. I want to get elevation from current latitude and longitude or current place only, but it will return whole path elevation.

var el = L.control.elevation();
el.addTo(map);
var gjl = L.geoJson(geojson,{
     onEachFeature: el.addData.bind(el)
}).addTo(map);
map.addLayer(service).fitBounds(bounds);

How can I find the elevation with either mapbox or leafletjs.

Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
Ved
  • 2,701
  • 2
  • 22
  • 30
  • What do you mean with current place only and current latitude and longitude? Looking at your code it seems that you are adding elevation to every feature element – kiks73 Dec 05 '17 at 08:57
  • elevation of current place only, above code return elevation of whole json data. – Ved Dec 05 '17 at 08:59
  • I want like this https://developers.google.com/maps/documentation/javascript/examples/elevation-simple – Ved Dec 05 '17 at 09:01

2 Answers2

4

Leaflet is a map display library, not a data API, not a elevation raster query library.

For this, you will have to rely in some kind of elevation dataset (which one is "better" depends on your definition of "better").

For example, see Getting Altitude(height from sea level) of my location in iphone SDK

Whether to use a service like that or whether you should have your own elevation dataset is up to you. In any case, Leaflet does not provide a favourite elevation query service by default (contrary to what Google Maps does, as it relies on Google's elevation datasets).

IvanSanchez
  • 18,272
  • 3
  • 30
  • 45
1

Extending on @IvanSanchez's answer, you'll need to integrate a service to grab the elevation from your point. One such library which will do this with Mapbox is https://github.com/mcwhittemore/mapbox-elevation

AndrewHarvey
  • 2,867
  • 11
  • 21