For Example
Dim Gm As New GoogleMap(LatitudineMinima, LongitudineMinima, LatitudineMassima, LongitudineMassima)
Dim img As Image
img = Gm.Image
If MyGoogleMaps Is Nothing Then
MyGoogleMaps = img
End If
Public Class GoogleMap
Private MyLatitudineMinima As Double
Private MyLatitudineMassima As Double
Private MyLongitudineMinima As Double
Private MyLongitudineMassima As Double
Private MySizeW As Integer = 640
Private MySizeH As Integer = 640
Private MyScale As Integer = 1
Private MyZoom As Integer = 14
Private MyMapType As String = "roadmap"
Private MySensor As Boolean = False
Private AddMarker As Boolean = True
Public Sub New(ByVal LatitudineMin As Double, ByVal LongitudineMin As Double, ByVal LatitudineMax As Double, ByVal LongitudineMax As Double)
MyLatitudineMassima = LatitudineMax
MyLatitudineMinima = LatitudineMin
MyLongitudineMassima = LongitudineMax
MyLongitudineMinima = LongitudineMin
End Sub
Private ReadOnly Property Url() As String
Get
Dim Str As String
Str = "http://maps.googleapis.com/maps/api/staticmap?center="
Str = Str & Coordinate.Avg(MyLatitudineMinima, MyLongitudineMinima, MyLatitudineMassima, MyLongitudineMassima).ToGoogle
Str = Str & "&zoom=" & MyZoom.ToString
Str = Str & "&size=" & MySizeW.ToString & "x" & MySizeH.ToString
Str = Str & "&scale=" & MyScale.ToString
Str = Str & "&maptype=" & MyMapType
If AddMarker Then
Str = Str & "&markers=color:green%7Clabel:G%7C" & Coordinate.Avg(MyLatitudineMinima, MyLongitudineMinima, MyLatitudineMassima, MyLongitudineMassima).ToGoogle
End If
Str = Str & "&sensor=" & MySensor.ToString.ToLower
Return Str
End Get
End Property
Public ReadOnly Property Image() As Image
Get
Dim ur As New System.Uri(Url)
Dim Wr As System.Net.WebRequest
Dim St As System.IO.Stream
Wr = System.Net.WebRequest.Create(ur)
Wr.Proxy = System.Net.WebRequest.GetSystemWebProxy
st = Wr.GetResponse.GetResponseStream
Using Br As New IO.BinaryReader(St)
Using fs As New IO.MemoryStream
' Dim buffer(1024) As Byte
Try
Do
fs.WriteByte(Br.ReadByte())
Loop
Catch Ex As System.IO.EndOfStreamException
'finito stream
Return System.Drawing.Image.FromStream(fs)
Finally
St.Close()
St.Dispose()
End Try
End Using
End Using
End Get
End Property
End Class