0

"ImportFile" error with Api Google Maps

Can someone explain me what is the error in the importFile-line?

"//Define some variables first";
let Loc1 := urlEncode(text(Location1));
let Loc2 := urlEncode(text(Location2));
let Loc3 := urlEncode(text(Location3));
let Center := urlEncode(text('Map-Center (if left emty = auto center)'));
"//Building URL field";
if 'Your-API-Key' = null then
alert("Please Enter a working API Key")
else
let myURL := "http://maps.google.com/maps/api/staticmap?" + if 'Map-Center (if left emty = auto center)' then
"center=" + Center
end + "&zoom=" + 'Zoom Ratio' + "&size=512x512&maptype=" + text(MapType) + "&markers=color:" + text(Color1) + "|label:" + text(Label1) + "|" + Loc1 + "&markers=color:" + text(Color2) + "|label:" + text(Label2) + "|" + Loc2 + "&markers=color:" + text(Color3) + "|label:" + text(Label3) + "|" + Loc3 + "&sensor=false&key=" + 'Your-API-Key';
"//Putting the URL in the URL-Field to display";
URL := myURL;
"//Delete the existing picture";
Map := null;
"//Getting the URL-image from internet and display it in the picture field";
importFile(this, URL, "map.png")
end

Image

7 replies

null
    • Walcher_Messebau_GmbH
    • 4 yrs ago
    • Reported - view

    I forgot to put the last line:

     

    Map := first(files(this))

    anyway..it doesn't work :(

    • Ninox partner
    • RoSoft_Steven.1
    • 4 yrs ago
    • Reported - view

    Are you using a valid API key?

    If not, you can open the created URL field manually to check if there's a map displayed or not.

    I've seen this code before BTW. The API key i've provided in the example database is no longer valid if that's the case...

    Steven.

    • Walcher_Messebau_GmbH
    • 4 yrs ago
    • Reported - view

    Hi Steven, Api is valid. I've updated Ninox and now it works :)

    Anyway, I'm trying now to calculate the distance between two point (2 ubication field) with this formula and the api is valid for distance matrix:

     

    let response := http("GET", "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=" + latitude(Fiera.Indirizzo) + longitude(Fiera.Indirizzo) + "&destinations=" + latitude(Indirizzo) + longitude(Indirizzo) + "&key=API KEY");
    if response.error then
    alert(text(response.error))
    else
    Distanza := text(response.result.rows.'0'.elements.'0'.distance.text)
    end

    Something doesn't work. I don't get any result in the text field DISTANZA. Do I have to manually insert latitude and longitude in the ubication fields?? If yes is there any trigger to make automaticly two fields with coordinates for each ubication field?

     

    Thanks

    • Walcher_Messebau_GmbH
    • 4 yrs ago
    • Reported - view

    The error when I press the button is "Request failed: error-"

    • Walcher_Messebau_GmbH
    • 4 yrs ago
    • Reported - view

    I've updated the code because there were a few erros. In bold what I've added:

     

    let response := http("GET", "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=" + 'Latitudine Fiera' + "," + 'Longitudine Fiera' + "&destinations=" + 'Latitudine Hotel' + "," + 'Longitudine Hotel' + "&key=AIzaSyA3_jo5cg0FHTjVtzbZ7L2kbHb7tRY9kt4");
    if response.error then
    alert(text(response.error))
    else
    Distance := text(response.result.rows.'0'.elements.'0'.distance.text)
    end

    Now I've made 2 formulafields with the latitude and longitude of each location and replaced that parts in the code but nothing changed. Always the same error

    • Walcher_Messebau_GmbH
    • 4 yrs ago
    • Reported - view

    I've canceled the Api I've posted before. I've checked the URL

     

    https://maps.googleapis.com/maps/api/distancematrix/json?origins=45.417552947998,10.9780826568604&destinations=45.3988304138184,11.0159778594971&key=

    I've replaced the comma with dots in the latitude and longitude.

    Before,with the comma, the result was:

     

    {
    "destination_addresses" : [ "" ],
    "origin_addresses" : [ "" ],
    "rows" : [
    {
    "elements" : [
    {
    "status" : "NOT_FOUND"
    }
    ]
    }
    ],
    "status" : "OK"
    }

     

    and now the result is:

    {
    "destination_addresses" : [ "Via Monte Pastello, 28, 37057 San Giovanni Lupatoto VR, Italia" ],
    "origin_addresses" : [ "Viale del Lavoro, 8, 37135 Verona VR, Italia" ],
    "rows" : [
    {
    "elements" : [
    {
    "distance" : {
    "text" : "5,0 km",
    "value" : 5048
    },
    "duration" : {
    "text" : "11 min",
    "value" : 684
    },
    "status" : "OK"
    }
    ]
    }
    ],
    "status" : "OK"
    }

     

    So, how can I replace the comma of latitude and longitude automatically?

    Anyway I don't get the result in the texfield "distance":(

    • Walcher_Messebau_GmbH
    • 4 yrs ago
    • Reported - view

    I found the formula to replace the comma with a dot

     

    replace (YourField,",",".")

    Has someone a solution to fix the error in the last two strings of the importfield? 😩

Content aside

  • 4 yrs agoLast active
  • 7Replies
  • 969Views