# Advanced Tutorial: Automatic Delivery Charge Based on Distance via Google Maps

**URL:** <https://forum.sambapos.com/t/advanced-tutorial-automatic-delivery-charge-based-on-distance-via-google-maps/6918>\
**Category:** V5 Tutorial\
**Created:** [September 6, 2015, 8:56pm UTC](https://forum.sambapos.com/t/advanced-tutorial-automatic-delivery-charge-based-on-distance-via-google-maps/6918 "2015-09-06T20:56:17Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![sukasem](https://forum.sambapos.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@sukasem](https://forum.sambapos.com/u/sukasem)\
**Post date:** [January 9, 2016, 4:37am UTC](https://forum.sambapos.com/t/advanced-tutorial-automatic-delivery-charge-based-on-distance-via-google-maps/6918/11 "2016-01-09T04:37:05Z")

</div>

It is easy.

```
function deliveryFee(origin,destination)

{
	var u = 'http://maps.googleapis.com/maps/api/distancematrix/json?origins='+origin+'.&destinations='+destination+'.&mode=driving&language=en-US&sensor=false&units=metric';
	var alldata = web.Download(u);
	var json = JSON.parse(alldata);
	var distance = json.rows[0].elements[0].distance.value;
	if (distance < 100) {
		var fee = 0;
	}
	if (distance >= 100 && distance < 1600) {
		var fee = 5;
	}
	if (distance >= 1600 && distance < 3100) {
		var fee = 6;
	}
	if (distance >= 3100 && distance < 6100) {
		var fee = 7;
	}
	if (distance >= 6100 && distance < 8100) {
		var fee = 8;
	}
	if (distance >= 8100) {
		var fee = -1;
	}	
	return fee;
}
```

---

_[View the full topic](https://forum.sambapos.com/t/advanced-tutorial-automatic-delivery-charge-based-on-distance-via-google-maps/6918)._
