### Thread: Calculating the distance in mile from Point A to Point B

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Aug 2012
Posts
25
Rep Power
0

#### Calculating the distance in mile from Point A to Point B

Hi, My cousin have a trucking business and he wants me to a page in his website that the people can type from to address and base on the miles between the address they get a quote. I bet there is a easy way to do this by using widget, but since I'm learning Python this will be a good project. Can you guys show me the right way to start this project. Thanks in advance.
2. I don't know if the geo-mapping databases are free. Therefor, and this might not be a global solution, I'd just have a program that accesses mapquest and parses its output.
3. No Profile Picture
Lost in code
Devshed Supreme Being (6500+ posts)

Join Date
Dec 2004
Posts
8,304
Rep Power
7174
The Google maps API can probably do everything you need.
4. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Aug 2012
Posts
25
Rep Power
0
I just finish to figure out. I'm using the google api with simplejson.Here is my code:

Code:
```import simplejson, urllib

geo_args.update({
'sensor': sensor
})

url = GEOCODE_BASE_URL + '?' + urllib.urlencode(geo_args)

print url
result2= result['routes'][0]['legs'][0]['distance']['text']
print ('This is the driving distance: ' + result2)
result2=result2.split(" ")
result2=result2[0]
print result2
result2=float(result2)
result2= float (result2*1.35)
print round(result2)
if __name__ == '__main__':
Now I have to figure out how to take the information provide by costumer and how to put it in the website. If you guys can help me with that part.
5. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2008
Posts
30
Rep Power
10
You are assuming that the trucks drive in a straight line like a bird - Unfortunately they dont, so the miles calculation will only give you a radius of a circle like some of the stores use to calculate their delivery fee. "If you live within 5 miles of the store the delivery fee is 5 dollars, if you live more than 5 and less than 10, it is 10 dollars" - that kind of thing.

If you need to work out the actual milage the truck will have to cover, and so work out the gas used, you may have to plug into a GPS or route database like they have in your car Garmin device etc
6. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Aug 2012
Posts
25
Rep Power
0
No, that script on the top give you the driving distance not the straight line.
7. No Profile Picture
Contributing User
Devshed Intermediate (1500 - 1999 posts)

Join Date
Feb 2004
Location
San Francisco Bay
Posts
1,939
Rep Power
1317
Originally Posted by ocpaul20

If you need to work out the actual milage the truck will have to cover, and so work out the gas used, you may have to plug into a GPS or route database like they have in your car Garmin device etc