1

I'm trying to develop a routing system and I want to know how can start with the user's current location from A point?

var control = L.Routing.control({
    //   waypoints: [null],
    waypoints: [
        L.latLng( user's current location),
        L.latLng(" string address")
    ],
    routeWhileDragging: true,
    show: true,
    language: 'it',
    geocoder: L.Control.Geocoder.nominatim(),
    autoRoute: true
}).addTo(map);
1

You need to retrieve the user coordinates to use them as input. In leaflet you can use e.latlng.lng and e.latlng.lat.
Using this, your example should look like this:

var control = L.Routing.control({
//   waypoints: [null],
waypoints: [
    L.latLng( e.latlng.lat, e.latlng.lng),
    L.latLng(" string address")
],
routeWhileDragging: true,
show: true,
language: 'it',
geocoder: L.Control.Geocoder.nominatim(),
autoRoute: true 
}).addTo(map)
  • Hi, I'll accept your answer but before that help with this, I have var latitude = position.coords.latitude; var longitude = position.coords.longitude; how can I assign these variables to e.latlng.lat and e.latlng.lng? – jamil Jun 21 '16 at 12:17
  • if you already have these variables just use those. e.latlng is leaflet's way of providing the coordinates. – Cristian Iosub Jun 22 '16 at 8:40

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.