Code: Select all
InitNetwork()
UsePNGImageDecoder()
Enumeration
#ROADMAP
#SATELLITE
#TERRAIN
#HYBRID
EndEnumeration
Procedure.l getMapImage( MapAddress.s, Zoom=15, MapType = #ROADMAP, Markers.s = "" )
RetVal = 0
If Markers <> ""
myRequestTwo.s = "/maps/api/staticmap?center="+ URLEncoder(MapAddress) + "&" + URLEncoder(Markers) + "&zoom=" + Str(Zoom) + "&size=500x500"
Else
myRequestTwo.s = "/maps/api/staticmap?center="+ URLEncoder(MapAddress) + "&zoom=" + Str(Zoom) + "&size=500x500"
EndIf
Select MapType
Case #SATELLITE
myRequestTwo.s + "&maptype=satellite"
Case #TERRAIN
myRequestTwo.s + "&maptype=terrain"
Case #HYBRID
myRequestTwo.s + "&maptype=hybrid"
Default
myRequestTwo.s + "&maptype=roadmap"
EndSelect
myRequestTwo.s + "&sensor=false"
myConnection = OpenNetworkConnection("maps.google.com", 80, #PB_Network_TCP)
If myConnection = 0
ProcedureReturn 0
EndIf
myRequest.s = "GET "+ myRequestTwo + " HTTP/1.0" + #CRLF$
myRequest.s + "Content-Type: application/x-www-form-urlencoded; charset=iso-8859-1" + #CRLF$
myRequest.s + "Host: maps.google.com" + #CRLF$ + #CRLF$
*buffer = AllocateMemory(65535)
*bufferTwo = AllocateMemory(65535)
bfTwoPtr = 0
mSize = 65535
SendNetworkString(myConnection, myRequest)
dwBytes = 1
While dwBytes > 0
dwBytes = ReceiveNetworkData(myConnection, *buffer, 65535)
If dwBytes > 0
If (*bufferTwo + dwBytes) >= mSize
mSize + 65535
*bufferTwo = ReAllocateMemory(*bufferTwo, mSize)
EndIf
CopyMemory(*buffer, (*bufferTwo+bfTwoPtr), dwBytes)
bfTwoPtr + dwBytes
EndIf
Wend
CloseNetworkConnection(myConnection)
FreeMemory(*buffer)
dblCrlf.s = #CRLF$+#CRLF$
found = 0
dataLength = 0
For k = 0 To bfTwoPtr
If k > bfTwoPtr
Break
EndIf
If PeekS(*bufferTwo+k, 4) = dblCrlf
found = k
headerInfo.s = PeekS(*bufferTwo, k)
dataBeginSpot = (k + 4)
*dataBegin = (*bufferTwo + dataBeginSpot)
dataLength = (bfTwoPtr - dataBeginSpot)
Break
EndIf
Next
If ((dataLength > 0) And (found > 0))
RetVal = CatchImage(#PB_Any, *dataBegin, dataLength)
EndIf
FreeMemory(*bufferTwo)
ProcedureReturn RetVal
EndProcedure
; MapAddress.s Can be a physical address or a set of Lat / Lon Coordinates like : "32.15648, -97.54235"
; Zoom: Googles Map Zoom Level from: 1 Less Zoom to I dunno...20? More Zoom....
; MapTypes:
;#ROADMAP
;#SATELLITE
;#TERRAIN
;#HYBRID
; Markers. Google draws your map with markers....Check Out Markers at: http://code.google.com/apis/maps/documentation/staticmaps/#MarkerLocations
myImage = getMapImage("Dallas, TX", 15, #HYBRID, "markers=color:blue|label:A|Dallas, TX&markers=color:red|label:B|5706 Lindell Ave, 75206")
If IsImage(myImage)
OpenWindow(0, 0, 0, 500, 500, "Test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(1, 0, 0, 500, 500, ImageID(myImage))
Repeat : Until WaitWindowEvent() = 16
FreeImage(myImage)
Else
MessageBox_(0, "Didn't get a map image!", "Hmm, Strange...", #MB_ICONERROR|#MB_OK)
EndIf