endpoint.awaitingGeocode = true;
- $.getJSON(OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json", function (json) {
+ var viewbox = map.getBounds().toBBoxString(); // <sw lon>,<sw lat>,<ne lon>,<ne lat>
+
+ $.getJSON(OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox, function (json) {
endpoint.awaitingGeocode = false;
endpoint.hasGeocode = true;
if (json.length === 0) {
$(".directions_form .reverse_directions").on("click", function () {
var from = endpoints[0].latlng,
- to = endpoints[1].latlng;
+ to = endpoints[1].latlng,
+ routeFrom = "",
+ routeTo = "";
+ if (from) {
+ routeFrom = from.lat + "," + from.lng;
+ }
+ if (to) {
+ routeTo = to.lat + "," + to.lng;
+ }
OSM.router.route("/directions?" + querystring.stringify({
from: $("#route_to").val(),
to: $("#route_from").val(),
- route: to.lat + "," + to.lng + ";" + from.lat + "," + from.lng
+ route: routeTo + ";" + routeFrom
}));
});