Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Latitude Longitude Address Geocoder Map WinHttp.WinHttpRequest Http Response ResponseText
;Winbatch 2013B - Geocoder return Latitude/Longitude for an address ; ;performs a simple HTTP query for a given address ; ;Stan Littlefield - August 9, 2014 ;/////////////////////////////////////////////////////////////////////////// GoSub udfs IntControl(73,1,0,0,0) ;sample - normally this would come from a database table a="1005 Gravenstein Hwy N" c="Sebastopol" s="CA" z="95472" address=StrReplace(a," ","+"):",+":c:"+":s:"+":z cURL="http://geocoder.us/demo.cgi?address=":address BoxOpen("Gathering Latitude/Longitude",cURL) oHTTP = CreateObject("WinHttp.WinHttpRequest.5.1") oHTTP.Open("GET", cURL, @FALSE) oHTTP.send() oHTTP.WaitForResponse() cResp=oHTTP.ResponseText oHTTP = 0 n=StrIndex(cResp,"https://maps.google.com/maps?q=",0,@FWDSCAN) If n>0 n1=StrSub(cResp,n,100) n1=StrSub(n1,1,StrIndex(n1,'"',0,@FWDSCAN)-1) n2=ItemExtract(2,n1,"=") lat=StrTrim(ItemExtract(1,n2,",")) long=StrTrim(ItemExtract(2,n2,",")) ;displays variables but these could be placed back into db table BoxText(n1:@CRLF:"Latitude: ":lat:@CRLF:"Longitude: ":long) TimeDelay(4) Else BoxText("Either Invalid Address or Lookup Failed" TimeDelay(2) EndIf Exit :WBERRORHANDLER oHTTP=0 ErrorProcessing(1,1,0,0) Exit :udfs #DefineSubRoutine ErrorProcessing(deleteIni,showerr,logfile,Err_Array) If VarType(Err_Array) ==256 WbError = Err_Array[0] wberrorhandlerline = Err_Array[1] wberrorhandleroffset = Err_Array[2] wberrorhandlerassignment = Err_Array[3] wberrorhandlerfile = Err_Array[4] wberrortextstring = Err_Array[5] wberroradditionalinfo = Err_Array[6] wberrorinsegment = Err_Array[7] Else WbError = LastError() EndIf WbTextcode = WbError If WbError==1668||WbError==2669||WbError==3670 WbError = ItemExtract(1,IntControl(34,-1,0,0,0),":") WbTextcode = -1 EndIf WbErrorString = IntControl(34,WbTextcode,0,0,0) WbErrorDateTime = TimeYmdHms() If deleteIni WbErrorFile = StrCat(ShortCutDir( 'AppData', 0, 0 ),'\WinBatch\Settings\') If ! DirExist(WbErrorFile) Then WbErrorFile = DirWindows(0) WbErrorFile = StrCat(WbErrorFile,"WWWBATCH.INI") FileDelete(WbErrorFile) IniWritePvt(WbErrorDateTime,"CurrentScript",WbErrorHandlerFile ,WbErrorFile) IniWritePvt(WbErrorDateTime,"ErrorValue" ,WbError ,WbErrorFile) IniWritePvt(WbErrorDateTime,"ErrorString" ,WbErrorString ,WbErrorFile) IniWritePvt(WbErrorDateTime,"ScriptLine" ,WbErrorHandlerLine ,WbErrorFile) IniWritePvt(WbErrorDateTime,"ScriptOffset" ,WbErrorHandlerOffset ,WbErrorFile) IniWritePvt(WbErrorDateTime,"VarAssignment",WbErrorHandlerAssignment,WbErrorFile) IniWritePvt(WbErrorDateTime,"VarInSegment" ,WbErrorInSegment,WbErrorFile) IniWritePvt("","","",WbErrorFile) EndIf WbErrorMsgText = StrCat(WbErrorDateTime,@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"Current Script: ",WbErrorHandlerFile,@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"Error# [",WbError,"]",@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"Error Text: ",wberrortextstring,@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"[Extended Information] ",wberroradditionalinfo,@CRLF,@CRLF) WbErrorMsgText = StrCat(WbErrorMsgText,"On Line:",@CRLF,WbErrorHandlerLine,@CRLF) ;WbErrorMsgText = StrCat(WbErrorMsgText,"Offset: ",WbErrorHandlerOffset,@CRLF) If (WbErrorHandlerAssignment>"") Then %WbErrorHandlerAssignment% = "UNKNOWN" WbErrorMsgText = StrCat(WbErrorMsgText,"Assignment/Variable: ",WbErrorHandlerAssignment,@CRLF) If (WbErrorInSegment>"") Then WbErrorMsgText = StrCat(WbErrorMsgText,"In UDF/UDS: ",WbErrorInSegment,@CRLF) If logfile cSep = StrCat(StrFill("=",50),@CRLF) cLogFile = StrCat(DirScript(),"log.err") If ! FileExist(cLogFile) Then FilePut(cLogFile,StrCat("Error Log",@CRLF,cSep)) FilePut(cLogFile,StrCat(FileGet(cLogFile),WbErrorMsgText,cSep)) Display(2,"An Error Occured",StrCat("written to ",cLogFile)) Else If showerr WbErrorMsgText = StrCat(WbErrorMsgText,"[THIS ERROR NOT WRITTEN TO LOG FILE]",@CRLF) Message("An Error Was Encountered",WbErrorMsgText) EndIf EndIf Return(1) #EndSubRoutine Return ;///////////////////////////////////////////////////////////////////////////////////////////////
Article ID: W18522
Filename: Geocoder Return Latitude and Longitude for an Address.txt
File Created: 2014:08:11:08:12:18
Last Updated: 2014:08:11:08:12:18