FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to create a delivery Route?
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
How to create a delivery Route?
Posted: Tue Jul 01, 2025 07:45 PM

Hi Guys,

I have several customers and I need to create, automatically, a delivery route for them, using their address. What is the best way to implement this?

Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to create a delivery Route?
Posted: Wed Jul 02, 2025 03:41 AM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: How to create a delivery Route?
Posted: Wed Jul 02, 2025 06:46 PM

Thank You Guys,

I saw several examples of google api use in this forum, but they are old and none of them is working anymore.

I know google has recently changed how its api works, and now a developer key is demanded, but i can't found samples of how to use it.

Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: How to create a delivery Route?
Posted: Thu Jul 03, 2025 01:42 AM
No comprendo muy bien lo que necesitas, pero estimo que es trazar una ruta con puntos intermedios en google maps, estoy en lo cierto?
De ser así tienes que usar la libreria visualization de la API de google, para lo cual necesitas tener creado tu Key en la plataforma.
De ser así, el código para crear el mapa con puntos intermedios es algo así:
<script type="text/javascript"> 
var geocoder;
var map;
var marker;
var latitud = -34.650550;
var longitud = -59.432123;
var latitud1 = -34.670778;
var longitud1 =  -59.379971;
var geolat; 
var geolon;
var options = {
  enableHighAccuracy: true,
  timeout: 10000,  
};
function success(pos) {
  var crd = pos.coords;
  geolat = crd.latitude;
  geolon = crd.longitude;  
};
function error(err) {
  geolat = -34.670778;
  geolon = -59.432123;
};
navigator.geolocation.getCurrentPosition(success, error, options);
function initialize() {    
  var latLng 
  latLng = new google.maps.LatLng(latitud,longitud);
  latLng1 = new google.maps.LatLng(latitud1,longitud1);
  const directionsService = new google.maps.DirectionsService();
  const directionsRenderer = new google.maps.DirectionsRenderer();
  map = new google.maps.Map(document.getElementById('mapCanvas'), {
    zoom: 12,
    center: latLng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });  
  directionsRenderer.setMap(map);
  geocoder = new google.maps.Geocoder();
  marker = new google.maps.Marker({
    position: latLng,
    map: map,
    draggable: false
  });
  marker = new google.maps.Marker({
    position: latLng1,
    map: map,
    draggable: false
  }); 
  directionsService.route(
    {
      origin: { lat: latitud, lng: longitud}, //Punto Inicial
      destination: { lat: latitud1, lng: longitud1 }, //Punto destino
      waypoints: [
                  { location: { lat: -34.650906454358896, lng:-59.42340476060634 } }, //Puntos intermedios
                  { location: { lat: -34.66448438913878, lng: -59.421480097620545 } }                  
                 ],
      travelMode: 'DRIVING'   
    },
    (response, status) => {
      if (status == "OK") {
        directionsRenderer.setDirections(response);
      } else {
        window.alert("Fallo " + status);
      }
    }
  );
}

// Onload handler to fire off the app.
google.maps.event.addDomListener(window, 'load', initialize); 
</script>
<script async defer
    src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&signed_in=true&libraries=visualization&callback=initMap">
</script>
Mira la documentacion de maps para mas detalles https://developers.google.com/maps/documentation/javascript/reference/directions?hl=es-419
Posts: 99
Joined: Thu Jul 12, 2007 02:02 PM
Re: How to create a delivery Route?
Posted: Thu Jul 03, 2025 10:23 AM
Hi Vilian,

try this
#include "Fivewin.ch"

FUNCTION Main()
        LOCAL   cBuf, cStartMun, cStartAddr, cEndtMun, cEndAddr
        
        cStartMun  := "Marbella"
        cStartAddr := "Avda. del Rosario 34-A"
        
        cEndtMun   := "Marbella"
        cEndAddr   := "Avenida Las Palmeras 8"
        
        cBuf := "http://maps.google.com/maps?saddr=" + GoogleMkInd( cStartMun, cStartAddr ) + "&daddr=" + GoogleMkInd( cEndtMun, cEndAddr )

        IF IsWinNT()
                Shellexecute( GetDesktopWindow(), "open", cBuf )
        ELSE
                WinExec( "start iexplore " + cBuf, 0 )
        ENDIF
RETURN NIL

FUNCTION GetWords( cBuf )
        LOCAL   nFind, aWords := {}
        
        cBuf += SPACE( 1 )
        
        DO WHILE .T.
                nFind := AT( " ", cBuf )
                
                IF nFind == 0
                        EXIT
                ELSE
                        cWord := ALLTRIM( LEFT( cBuf, nFind - 1 ) )
                        
                        IF .NOT. EMPTY( cWord )                                        
                                AADD( aWords, cWord )
                        ENDIF
                        
                        cBuf := SUBSTR( cBuf, nFind + 1 )        
                ENDIF
        ENDDO
RETURN aWords

FUNCTION GoogleMkInd( cComune, cIndir )
        LOCAL   cBuf := "", aWords

        cComune := ALLTRIM( cComune )

        cIndir := STRTRAN( cIndir, ",", " " )

        aWords := GetWords( cIndir )

        AEVAL( aWords, { | arr, nIndex | IIF( nIndex > 1, cBuf += "+", ), cBuf += arr } )

        cBuf += "+" + STRTRAN( cComune, " ", "%20" )
RETURN cBuf
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: How to create a delivery Route?
Posted: Thu Jul 03, 2025 11:22 AM

Thank you Guys,

I will try it next week.

Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil

Continue the discussion