Options

Calculate distance from post codes

edo906edo906 Member Posts: 7
Hi,

I need to know how to calculate a distance between two postal codes (location table and sales shipment header-ShiptoCity) and know the distance and put it in a field of a custom table. How can I do? In case if I were to use a webservice, how do I implement it on nav?
For nav 2018

Thanks so much

Answers

  • Options
    txerifftxeriff Member Posts: 492
    edited 2021-12-21
    you just forgot to ask "how do I become an astronaut, can anyone tell me what I have to do?".

    First, yes you will need to locate a WS for this, google a bit:

    https://gis.stackexchange.com/questions/15199/looking-for-free-web-service-that-calculates-driving-distance-between-2-addresse/296403

    https://developers.google.com/maps/documentation/distance-matrix/overview

    I suggest you download postman:
    https://www.postman.com/

    you will need it to figure out WS calls and make it work.

    Once you have this, you "translate this to NAV".

    There are several ways to do WS calls to NAV, depending on the version (winhttps, AL...)


    n1wn6ingkw1d.png


    "basic" winhttp example
    
    IF ISCLEAR(WinHTTP) THEN
      CREATE(WinHTTP,TRUE,TRUE);
    
    WinHTTP.Open('POST',T50161."PayPal URL"+'oauth2/token', FALSE);
    
    WinHTTP.SetRequestHeader('Accept', 'application/json');
    WinHTTP.SetRequestHeader('Accept-Language', 'en_US');
    WinHTTP.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    WinHTTP.SetRequestHeader('Authorization', STRSUBSTNO('Basic %1', T50161."Base64 Client and Secret"));
    WinHTTP.Send('grant_type=client_credentials');
    
    vInStream := WinHTTP.ResponseStream;
    REPEAT
      vInStream.READTEXT(vtext);
      vBigT.ADDTEXT(vtext);
    UNTIL (vInStream.EOS);
    
Sign In or Register to comment.