Hello,
I am in need of guidance regarding calculating the distance “in miles” between a pickup and dropoff destination.
For the “Backend”
import {fetch} from ‘wix-fetch’ ;
export function distance() {
const key = “AIdvSyDypwabcgedtE_F4rdg-cLhlmnU” ;
const url = “https://maps.googleapis.com/maps/api/distancematrix/json” ;
const DistanceUrl = url + “?origins=” + $w( “#pickupAddress” ).value + “&destinations=” + $w( “#dropoffAddress” ).value + “&key=” + key;
return fetch (url, {method: ‘get’ }).then( (httpResponse) => {
if (httpResponse.ok) {
console.log( “OK” );
return httpResponse.json();
}
})
}
My understanding of this code is:
we are constructing the URL that will fetch information from maps. googleapis and will fill in the search query for ?origins= and &destinations= to form a COMPLETE URL and Results Such as:
and this will generate a response in the URL of the following JSON:
{
“destination_addresses” : [ “New York, NY, USA” ],
“origin_addresses” : [ “Washington, DC, USA” ],
“rows” : [
{
“elements” : [
{
“distance” : {
“text” : “367 km”,
“value” : 367441
},
“duration” : {
“text” : “3 hours 52 mins”,
“value” : 13948
},
“status” : “OK”
}
]
}
],
“status” : “OK”
}
now, for my “Page Code”
import {distance} from ‘backend/gapi’ ;
export function Calculate_click(event) {
distance().then( function (resp) {
console.log(resp);
});
}
My understanding is when “Calculate” is clicked, It will import the DATA from my BACKEND code and log the results.
Here is my problem:
I cannot figure out how to correctly code this information.
I have 2 address inputs & 1 button
1 = Pickup Location
2 = Dropoff Location
Button = “Calculate” on-click
I simply need help getting the “Distance in miles” between the two locations on click.
I have setup my API and enabled Places, Geolocation, Gecoding, Maps Javascript etc and Billing has also been enabled.
Here is a link to my original post 1 week ago, which includes screenshots if necessary
I have also reached out to HIRE wix experts using Wix’s platform and everyone I have reached out to has not responded.
It is frustrating to see employees of Wix respond to users after just 30 minutes of posting into the forum and I have waited a week and was told I have a limited amount of times I can ask for assistance, without my posts for “HELP” being internally deleted.
I recruit TONS of business to wix and have transferred many clients over to their platform. As a loyal patron of WIX, all I am seeking is guidance from the very platform that advertises its willingness to help.
My emails to wix support are ignored. Setting up phone call requests have been ignored. and now my forum posts are being ignored.
It is becoming clear that wix is no longer a platform willing to help assist its users & developers. You are on your own.