I am using Leaflet Map with geocoder (ESRI) and Routing Machine. I have added two markers, let's say my home and my work
var marker_work = L.marker([50.27, 19.03], { title: 'MyWork'}).addTo(map)
.bindPopup("work").openPopup();
var marker_home = L.marker([50.10, 18.4], { title: 'MyHome'}).addTo(map)
.bindPopup("home").openPopup();
Here is an example fiddle: https://jsfiddle.net/21nmk8so/1/
How can I add this markers/point as a predefined places for ControlGeocoder? I want to use them in search and use as a start point / end point for route calculation.
Another example for the same question: how to add custom-fake city with lat/lon and be able to search (find route) to/from that city.
I don't know if this is the best solution but it is working: Create a custom Geocoder Class which overwrites the
geocode
function. There you can overwrite the result function and apply suggestions to the result.Then you have to use the new Geocoder Class:
And finally you can add suggestions over markers and theier
title
option overcreateSuggestionFromMarker(marker)
orsetSuggestions(arr)
:Update, use marker Ref instead of fix latlng
Change this two function, then the marker is referenced and it always searches from the current position of the marker:
You can test this in the demo, when you drag the marker
https://jsfiddle.net/falkedesign/hu25jfd1/