Ninox – navigate to address using Google maps / Ninox – mit Google maps zu einer Adresse navigieren

Mit diesem Ninox code könnt ihr via Google maps zu einer bestimmten Adresse navigieren. Das Verhalten unterscheidet sich ob Ninox im Browser (web) betrieben wird oder mit der Apple- oder Android-App.
Beim klick auf den Button „Navi“ vom Browser aus wird von einer bestimmten, festgelegten Adresse aus dort hin navigiert, vom Smartphone aus immer von der aktuellen Position aus.

Step 1) In den „Admin-Modus“ wechseln (Schlüsselsymbol oben rechts) und die Datenbank  (hier „Kontaktmanagement“) anklicken. Es erscheint die Auswahlmöglichkeit „Optionen“:

Folgenden Code unter „Globale Funktionen“ hinzufügen.

function SlashReplace(myText : text) do
   myText := replacex(myText, "/", "g", "%2F");
   myText
end

Step 2) Füge in deinem Formular ein Layout-Feld (Button) ein und benenne ihn mit „Navi“

Step 3) Bearbeite den Button „Navi“ und füge unter „Erweitert“ in die Zeile „Feld nur anzeigen, wenn“ folgenden Code ein: length(trim(‚Straße‘)) > 0 dies dient dazu den Button nur dann anzuzeigen wenn eine Straße eingetragen ist.

Füge in die Zeile „Beim Klicken“ folgenden Code ein (du musst natürlich den Code noch auf deine Datenfelder anpassen!). Schrägstriche ( / ) müssen konvertiert werden, siehe hierzu die Funktion SlashReplace() in den „Gobalen Funktionen“ (siehe oben):

let myMapsLocationURL := "";
if length(trim('Straße')) = 0 then
   alert("Navigation nicht möglich, keine Straße eingetragen!")
else
if ninoxApp() = "web" then
   myMapsLocationURL := "https://www.google.de/maps/dir/Schloßpl.+2,+70173+Stuttgart/" +
   (SlashReplace(trim('Straße')) + ",+" + SlashReplace(trim(Plz)) + "+" +
   SlashReplace(trim(Ort)))
else
   myMapsLocationURL := "https://www.google.de/maps/dir//" +
   (SlashReplace(trim('Straße')) + ",+" + SlashReplace(trim(Plz)) + "+" +
   SlashReplace(trim(Ort)))
end;
if length(trim(Land.Land)) > 0 then
   myMapsLocationURL := myMapsLocationURL + ",+" + SlashReplace(trim(Land.Land))
end;
myMapsLocationURL := myMapsLocationURL + "/&dir_action=navigate";
openURL(myMapsLocationURL)
end

Step 4) Einen Datensatz auswählen und auf den Button „Navi“ klicken. Die Google maps URL wird generiert und Google maps öffnet sich mit der Route vom Start (im Browser von der fest vorgegebenen Adresse im Code (hier: Schloßpl. 2, 70173 Stuttgart) zur Zieladresse aus dem aktuell gewählten Ninox Datensatz.

Viel Erfolg mit der Navi-Funktion und ich würde mich über Feedback freuen 🙂


English version

With this Ninox code you can navigate to a specific address via Google maps. The behavior differs whether Ninox is running in the browser (web) or on the Apple or Android app.
When you click on the “Navi” button from the browser, you navigate from a specific, fixed address, (here: Schloßpl. 2, 70173 Stuttgart) and on a smartphone always from the current position.

Step 1) Switch to “Admin mode” (key symbol at the top right) and click on the database (here “Contact Management”). The “Options” selection appears:

Add the following code under Global Functions.

function SlashReplace(myText : text) do
myText := replacex(myText, "/", "g", "%2F");
myText
end

Step 2) Add a layout field (button) to your form and name it “Navi”


Step 3) Edit the „Navi“ button and under „Advanced“ in the line „Show field only if“ enter the following code: length(trim(‚Street‘)) > 0 this is used to only display the button if a street is entered.

Insert the following code into the “On Click” line (of course you still have to adapt the code to your data fields!). Slashes ( / ) must be converted, see the SlashReplace() function in the “Global Functions” (see above):

myMapsLocationURL := "";
if length(trim('Street')) = 0 then
   alert("Navigation not possible, no street entered!")
else
if ninoxApp() = "web" then
   myMapsLocationURL := "https://www.google.de/maps/dir/Schloßpl.+2,+70173+Stuttgart/" +
   (SlashReplace(trim('Street')) + ",+" + SlashReplace(trim(Zip)) + "+" +
   SlashReplace(trim(location)))
else
   myMapsLocationURL := "https://www.google.de/maps/dir//" +
   (SlashReplace(trim('Street')) + ",+" + SlashReplace(trim(Zip)) + "+" +
   SlashReplace(trim(location)))
end;
if length(trim(Country.Country)) > 0 then
   myMapsLocationURL := myMapsLocationURL + ",+" + SlashReplace(trim(Country.Country))
end;
myMapsLocationURL := myMapsLocationURL + "/&dir_action=navigate";
openURL(myMapsLocationURL)
end

Step 4) Select a data set and click on the “Navi” button. The Google maps URL is generated and Google maps opens with the route from the start (in the browser from the fixed address in the code (here: Schloßpl. 2, 70173 Stuttgart) to the destination address from the currently selected Ninox record.

Good luck with the navigation function and I would be happy to receive feedback 🙂