WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WinHttpRequest

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Bing Maps Sample

 Keywords:  Bing Map REST WinHttp.WinHttpRequest.5.1 WinHttp WinHttpRequest API

Requirements: a Bing key/appID, which you get for free, although number of daily queries is limited.
;Winbatch 2011A - Bing Maps sample script
;
;Purpose: use the Bing Maps REST API to acquire a static map
;         The Bing API is a bit different from Google or Yahoo but
;         once you get the hang of it the returns are decent and
;         quit fast.
;         Does require a Bing key/appID, which you get for free, although
;         number of daily queries is limited.
;
;         This example draws a map of downtown Stamford, CT, saves it
;         to disk and displays in a COM Control
;
;         see: http://msdn.microsoft.com/en-us/library/ff701724.aspx
;              for an explanation of the parameters involved with
;              several test examples.
;
;Stan Littlefield September 30, 2011
;////////////////////////////////////////////////////////////////////////////////////////////////////////
;Acccount Id :1040153
GoSub udfs
IntControl(73,1,0,0,0)

cFile = DirScript():"bingmap.jpg"
key="{your bing key"

;static maps are drawn from a base address
base="http://dev.virtualearth.net/REST/v1/Imagery/Map/"

;other parameters
cI = "Road" ; other types Aerial – Aerial imagery or AerialWithLabels.
                        ; Road - roads without additional imagery.
                        ; OrdnanceSurvey --Ordnance Survey imagery.
                        ; CollinsBart – Collins Bart imagery.
;centerpoint - long/lat from query or lookup database, i.e. zipcode
cP = "41.0535,-73.5394"
;pushpin (optional) - up to 18 allowed, combination of centerpoint + ; + icontype + ; + label
pp = cP:";29;"
;map size - optional - default is 350,350
ms = "700,700"
;zoom (from 1-22) ;though I couldn't go beyon 19
zoom = "15"

;NOTE: some parameters are added with / rather than part of the ?
;      this is a bit confusing at first
cURL=base:cI:"/":cP:"/":zoom:"?pushpin=":pp:"&ms=":ms:"&key=":key

;create simple HTTP request
oHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
oHTTP.Open("GET", cURL, @FALSE)
oHTTP.Send()
oHTTP.WaitForResponse()

img = oHTTP.ResponseBody
oHTTP = 0
buf = BinaryAllocArray(img)
data = BinaryWrite(buf, cFile)
BinaryFree(buf)

cHTM='<html><body><img src="':cFile:'"</img></body></html>'
displaymap()

Exit

:WBERRORHANDLER
oHTTP=0
ErrorProcessing(1,1,0,0)
Exit


:udfs
#DefineSubRoutine displaymap()
MAPFormat=`WWWDLGED,6.2`

MAPCaption=`Bing API Static Map`
MAPX=9999
MAPY=9999
MAPWidth=308
MAPHeight=227
MAPNumControls=002
MAPProcedure=`dlgproc`
MAPFont=`DEFAULT`
MAPTextColor=`DEFAULT`
MAPBackground=`DEFAULT,DEFAULT`
MAPConfig=0

MAP001=`001,001,304,012,PUSHBUTTON,"OK",DEFAULT,"Click Here To Exit",1,10,160,DEFAULT,DEFAULT,"255|128|0"`
MAP002=`001,013,306,210,COMCONTROL,"map",DEFAULT,"MSHTML:",DEFAULT,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

BP=Dialog("MAP")



Return(1)

#EndSubRoutine

#DefineSubRoutine dlgproc(handle,msg,id,p4,p5)
IntControl(73,1,0,0,0)
Switch msg
   Case 0
      oIE=DialogObject(handle,"map",3)
      DialogProcOptions(handle,2,1)
      oIE.Writeln(cHTM)
      Break
   Case 2
      oIE.Close()
      oIE=0
      Return(9)
      Break
EndSwitch
Return(-2)

:WBERRORHANDLER
ErrorProcessing(1,1,0,0)
Return(9)

#EndSubRoutine



#DefineFunction isObject(obj)
Return(VarType(obj)>=1024)
#EndFunction

#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:   W18206
Filename:   Bing Maps Sample.txt
File Created: 2011:09:30:09:27:50
Last Updated: 2011:09:30:09:27:50