This did it for me:
Clicking the "find the route button from my position to the targets position" calls this function:
createRoute = function(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(getRoute);
} else {
alert("Geolocation not supported");
}
};
The modified getRoute function looks like this:
getRoute = function(position){
userLatitude = position.coords.latitude;
userLongitude = position.coords.longitude;
dir = MQ.routing.directions()
.on('success', function(data) {
//does some stuff with the routes data/directions. not important here
});
dir.route({
locations: [
{ latLng: { lat: userLatitude, lng: userLongitude } },
{ latLng: { lat: (poiCoordinates.lat), lng: (poiCoordinates.lng) } }
],
options: {
//not important as well
}
});
mqroute = MQ.routing.routeLayer({
directions: dir,
}).addTo(map);
};