Type=Class Version=5.8 ModulesStructureVersion=1 B4A=true @EndOfDesignText@ 'Class module #Event : DragEnd(NewLatitude As String , NewLongitude As String) #Event : Closed(args as list) #Event : Cancelled Sub Class_Globals Private lat,lon,modEvent,myhtml,okstring,cancelstring,mprompt As String Private mappanel As Panel Private modActivity As Activity Private mapweb As WebView Private mapxtra As WebViewExtras Private closemap,savepos As Button Private mymodule As Object Private mleft,mtop,mwidth,mheight,zoom As Int Private My_MapType_Id As String Private num As Int = 0 End Sub 'displays Google Earth satellite images Public Sub getSATELLITE Return "google.maps.MapTypeId.SATELLITE" End Sub 'displays the default road map view Public Sub getROADMAP Return "google.maps.MapTypeId.ROADMAP" End Sub 'displays a physical map based on terrain information Public Sub getTERRAIN Return "google.maps.MapTypeId.TERRAIN" End Sub 'displays a mixture of normal and satellite views Public Sub getHYBRID Return "google.maps.MapTypeId.HYBRID" End Sub 'Initializes the Map. 'act = Your activity or panel 'Module = calling module to receive Map Events. 'Ok = Ok button.Text. 'cancel = Cancel button.Text 'startlat = The starting Latitude . 'startlon = The starting Longitude . 'event = Event Prefix for map events. 'prompt = Text to show above the map . Pass empty string for larger map. 'mapzoom = zoom level : larger = closer . 'MapTypeId = Google Map Types 'You can use the following: 'WepMapView.ROADMAP displays the default road map view. This is the default map type. 'WepMapView.SATELLITE displays Google Earth satellite images 'WepMapView.HYBRID displays a mixture of normal AND satellite views 'WepMapView.TERRAIN displays a physical Map based on terrain information. Public Sub Initialize(act As Panel, Module As Object,Ok As String,cancel As String,startlat As String,startlon As String,event As String,prompt As String,mapzoom As Int,MapTypeId As String) zoom=mapzoom My_MapType_Id=MapTypeId ' ToastMessageShow(My_MapType_Id,True) myhtml="
".Replace("~",QUOTE) okstring=Ok cancelstring=cancel If okstring.Length>0 Then num=num+1 End If If cancelstring.Length>0 Then num=num+1 End If modActivity=act lat=startlat lon=startlon modEvent=event mappanel.Initialize("mappanel") mapweb.Initialize("mapweb") mymodule=Module mleft=modActivity.Left mtop=modActivity.Top mwidth=modActivity.Width mheight=modActivity.Height mprompt=prompt End Sub 'Add the map to the activity 'Typically used after Initializing the map Sub Show_Me Show_Map End Sub 'Remove map view from its parent Sub Remove_Me mappanel.RemoveAllViews mappanel.RemoveView End Sub Private Sub Show_Map mappanel.Color=Colors.White Dim tempnum As Int =num If tempnum>1 Then tempnum=tempnum-1 End If modActivity.AddView(mappanel,0, 0,mwidth,mheight) If mprompt.Trim.Length>0 Then Private mylbl As Label mylbl.Initialize("mylbl") mylbl.Gravity=Gravity.CENTER mylbl.Typeface=Typeface.DEFAULT_BOLD mylbl.textColor=Colors.Black mylbl.Text=mprompt mappanel.AddView(mylbl,0,0,(100*mwidth/100),10*(mheight/100)) mappanel.AddView(mapweb,0,10*(mheight/100),100*(mwidth/100),80*(mheight/100)) Else mappanel.AddView(mapweb,0,0*(mwidth/100),100*(mwidth/100),90*(mheight/100)) End If If num<1 Then mappanel.Height=mheight mapweb.Height=mheight End If mapweb.LoadHtml(myhtml) mapxtra.addJavascriptInterface(mapweb,"B4A") Dim div As Int=(100/num) Dim left As Int=0 ' ToastMessageShow(div,False) If cancelstring.Length>0 Then closemap.Initialize("closemap") closemap.Text=cancelstring mappanel.AddView(closemap,left+(mwidth/100)*div-(div*(mwidth/100)),100*(mheight/100)-10*(mheight/100), div*(mwidth/100),10*(mheight/100)) left=left+div*(mwidth/100) End If If okstring.Length>0 Then savepos.Initialize("savepos") savepos.Text=okstring mappanel.AddView(savepos,left+(mwidth/100)*div-(div*(mwidth/100)),100*(mheight/100)-10*(mheight/100), (100/num)*(mwidth/100),10*(mheight/100)) End If End Sub Private Sub mapweb_PageFinished (Url As String) Add_Marker(Array As String(lat,lon)) End Sub Private Sub closemap_Click Close_All If SubExists( mymodule,modEvent&"_Cancelled") = True Then CallSub(mymodule,modEvent&"_Cancelled") End If End Sub Private Sub savepos_Click Close_All If SubExists( mymodule,modEvent&"_Closed") = True Then ' Dim args As List ' args.Initialize ' args.AddAll(Array(,mapweb.CaptureBitmap)) CallSub3(mymodule,modEvent&"_Closed",lat,lon) End If End Sub Private Sub Add_Marker(latlon As List) Dim lat As String=latlon.get(0) Dim lon As String=latlon.get(1) Dim arg As String="addMarker("&lat&","&lon&");" mapxtra.executeJavascript(mapweb,arg) End Sub Private Sub Marker_DragEnd(NewLatitude As String, NewLongituden As String) ' only String types can be passed from the javascript to B4A so we need to convert the String types to Double lat=NewLatitude lon=NewLongituden If SubExists( mymodule,modEvent&"_DragEnd") = True Then CallSub3(mymodule,modEvent&"_DragEnd",NewLatitude,NewLongituden) End If End Sub Private Sub Close_All mappanel.RemoveAllViews mappanel.RemoveView End Sub 'Reset marker and map center to New Latitude and Longitude provided . Sub Reset_Location(newlat As String,newlon As String) Dim newhtml As String="
".Replace("~",QUOTE) lat=newlat lon=newlon mapweb.LoadHtml(newhtml) End Sub 'Set Map view type like "google.maps.MapTypeId.ROADMAP" Sub SetMapType(MapType As String) My_MapType_Id=MapType Dim newhtml As String="
".Replace("~",QUOTE) mapweb.LoadHtml(newhtml) End Sub Sub getPanel As Panel Return mappanel End Sub