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?
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?
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.
<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>#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 cBufThank you Guys,
I will try it next week.