# Useing Google Maps to calculate mileage from Point A to Point B

## Recommended Posts

I am new! Pick it apart and help me make it Better!

#include <IE.au3>

#include <GUIConstants.au3>

#Region ### START Koda GUI section ###

\$Form1= GUICreate("How many Miles?", 377, 248, 194, 116)

GUISetCursor (2)

\$txtfromAdd = GUICtrlCreateInput("", 8, 48, 153, 21)

\$Label1 = GUICtrlCreateLabel("From:", 8, 8, 45, 24)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

\$Label2 = GUICtrlCreateLabel("Street Address", 8, 32, 73, 17)

\$txtfromcity = GUICtrlCreateInput("", 8, 96, 153, 21)

\$Label3 = GUICtrlCreateLabel("City", 8, 80, 21, 17)

\$txtfromstate = GUICtrlCreateInput("", 8, 144, 153, 21)

\$Label4 = GUICtrlCreateLabel("State", 8, 128, 29, 17)

\$txttoAdd = GUICtrlCreateInput("", 216, 48, 153, 21)

\$Label5 = GUICtrlCreateLabel("To:", 216, 8, 26, 24)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

\$Label6 = GUICtrlCreateLabel("Street Address", 216, 32, 73, 17)

\$txttocity = GUICtrlCreateInput("", 216, 96, 153, 21)

\$Label7 = GUICtrlCreateLabel("City", 216, 80, 21, 17)

\$txttostate = GUICtrlCreateInput("", 216, 144, 153, 21)

\$Label8 = GUICtrlCreateLabel("State", 216, 128, 29, 17)

\$BtnCalc = GUICtrlCreateButton("Calculate", 240, 192, 105, 25)

GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")

\$lblMilage = GUICtrlCreateLabel("", 88, 192, 103, 28)

GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")

\$Label9 = GUICtrlCreateLabel("Distance =", 8, 195, 80, 24)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

\$VMap = GUICtrlCreateButton("View Map", 256, 224, 73, 17, 0)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

\$nMsg = GUIGetMsg()

Switch \$nMsg

Case \$GUI_EVENT_CLOSE

Exit

EndSwitch

If \$nMsg = \$BtnCalc Then Mileage()

If \$nMsg = \$VMap Then Map()

WEnd

Func Mileage()

GUICtrlSetData(\$lblMilage,"")

GUISetCursor(15)

\$Start = (\$fadd & ", " & \$fcity & " " & \$fstate)

\$End = (\$tadd & ", " & \$tcity & " " & \$tstate)

\$oIE = _IECreate(\$sUrl,0,0)

\$oDiv = _IEGetObjById(\$oIE, "dditd")

\$Result = (_IEPropertyGet(\$oDiv, "innertext"))

\$data = StringRegExp(\$Result, "([0-9]+.[0-9]+)",1)

If \$data = "" Then

MsgBox(0, "Mileage Calculation Error", "Mileage Calculation Error")

Map()

Else

GUICtrlSetData(\$lblMilage,\$data[0] & " Miles")

_IEQuit (\$oIE)

GUISetCursor(2)

EndIf

EndFunc

Func Map()

GUISetCursor(15)

\$Start = (\$fadd & ", " & \$fcity & " " & \$fstate)

\$End = (\$tadd & ", " & \$tcity & " " & \$tstate)

\$oIE = _IECreate(\$sUrl,0,1)

GUISetCursor(2)

EndFunc

[topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!

##### Share on other sites

Would be better if you learned theory of graphs and made a programm that actually calculates mileage

##### Share on other sites

Would be better if you learned theory of graphs and made a programm that actually calculates mileage

Nah, really, get yourself a pedometer and walk off the distance.

Recently discussed... see here: http://www.autoitscript.com/forum/index.ph...st&p=671222

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

Automate input type=file (Related)

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

##### Share on other sites

The script works fine, I was hoping to get some constructive criticism. Anyone?

[topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!

##### Share on other sites

Just some ideas...

Embed it

List directions

get weather

altitude

printable

???

8)

##### Share on other sites

@KenNichols

Well done

First thing to would be to check if the website is replying in Miles or KM.

Cheers

NBJ

##### Share on other sites

As identified in this topic...

Because Google appears to have updated the way they code their html, simply change "dditd" to "altroute_0" in the above code. Can get altroute_1 or altroute_2 as well if those are presented.

## Create an account

Register a new account

×

• Wiki

• Back

• Git