September 27th, 2012, 03:11 PM
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.
September 27th, 2012, 09:14 PM
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.
[/code] are essential for python code and Makefiles!
September 27th, 2012, 10:29 PM
The Google maps API can probably do everything you need.
September 28th, 2012, 12:01 AM
I just finish to figure out. I'm using the google api with simplejson.Here is my code:
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.
import simplejson, urllib
GEOCODE_BASE_URL = 'http://maps.googleapis.com/maps/api/directions/json'
def geocode(start_address,end_address, sensor, **geo_args):
url = GEOCODE_BASE_URL + '?' + urllib.urlencode(geo_args)
result = simplejson.load(urllib.urlopen(url))
print ('This is the driving distance: ' + result2)
result2= float (result2*1.35)
if __name__ == '__main__':
September 28th, 2012, 01:42 AM
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
September 28th, 2012, 07:31 AM
No, that script on the top give you the driving distance not the straight line.
September 28th, 2012, 12:43 PM
...or Google maps.
Originally Posted by ocpaul20