Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
v:2.0:shipping:custom_code:google_maps_distance [2020/06/11 22:20] – [Generate Google Maps Platform API Key] marija | v:2.0:shipping:custom_code:google_maps_distance [2020/12/09 20:44] (current) – [Build custom shipping code] adam | ||
---|---|---|---|
Line 56: | Line 56: | ||
// Get address coordinates from Google Maps | // Get address coordinates from Google Maps | ||
- | const maps_url = ' | + | const maps_url = ' |
let distance = -1; | let distance = -1; | ||
await request(maps_url, | await request(maps_url, | ||
Line 82: | Line 82: | ||
- If you need Imperial measurements rather than Metric, update the '' | - If you need Imperial measurements rather than Metric, update the '' | ||
- Google returns the distance value in metres in their API. The '' | - Google returns the distance value in metres in their API. The '' | ||
- | - Next, you'll need to set the shipping rate and error that is displayed to customers. The snippet above sets a rate that is $5 plus 45¢ per mile/km, but you'll obviously want to customise that to show your own rates. Check out [[..:shipping: | + | - Next, you'll need to set the shipping rate and error that is displayed to customers. The snippet above sets a rate that is $5 plus 45¢ per mile/km, but you'll obviously want to customise that to show your own rates. Check out [[..: |
if (distance > -1) { | if (distance > -1) { | ||
// Distance was calculated | // Distance was calculated |