Hi there,
i want for example see live tracking of my car in Google Maps... but don't have white screen in the middle (refreshing page - from blank)... I was hope if having two (2) webviews and checking progress will pass this problem - but the problem stills...
See my code if you can help me:
i want for example see live tracking of my car in Google Maps... but don't have white screen in the middle (refreshing page - from blank)... I was hope if having two (2) webviews and checking progress will pass this problem - but the problem stills...
See my code if you can help me:
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Timer3 As Timer
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim WebView1 As WebView
Dim WebView2 As WebView
Dim w As Long
Dim SeekBar1 As SeekBar
Dim Button1 As Button
Dim PosLat, PosLong As List
Dim lat As Float
Dim lng As Float
Dim WebViewExtras1 As WebViewExtras
Dim WebViewExtras2 As WebViewExtras
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("showatmap")
WebView1.Left =0
WebView1.Top = 0
WebView1.Width = 100%x
WebView1.Height = 100%y - Button1.Height
WebView2.Left =0
WebView2.Top = 0
WebView2.Width = 100%x
WebView2.Height = 100%y - Button1.Height
Button1.Top = WebView1.Height
Button1.Left = 50%x
Button1.Width = 50%x
SeekBar1.Left = 0
SeekBar1.Top = WebView1.Height
SeekBar1.Width = 50%x
If Main.lbllat.Trim = "" OR Main.lblLat.Trim="0" OR Main.lbllon.Trim = "" OR Main.lblLon.Trim="0" Then
Msgbox("Not having Lat and Long from GPS - check your GPS!","Προσοχή!")
ExitApplication
End If
WebViewExtras1.addWebChromeClient(WebView1, "WebViewExtras1")
WebViewExtras2.addWebChromeClient(WebView2, "WebViewExtras2")
PosLat.Initialize
PosLong.Initialize
PosLat.clear
PosLong.clear
lat=Main.lblLat
lng=Main.lbllon
PosLat.Add(lat)
PosLong.Add(lng)
ShowMap(lat, lng, SeekBar1.Value, False, False, False, "TOP_LEFT", True, PosLat, PosLong, True, False, "#ff0000", 0.5, 3)
w=1
Timer3.Initialize("Timer3",5000)
Timer3.Enabled = True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
ExitApplication
End Sub
Sub ShowMap(CenterLat As Float, CenterLong As Float, Zoom As Int, MapTypeControl As Boolean, DispZoomControl As Boolean, DispScaleControl As Boolean, ScaleControlPosition As String, DispMarkerCenter As Boolean, MarkerLat As List, MarkerLong As List, DispMarkers As Boolean, DispPolyline As Boolean, PolyLineColor As String, PolyLineOpacity As Float, PolyLineWidth As Int)
' CenterLat = latitude of map center in degrees
' CenterLong = longitude of map center in degrees
' Zoom = zomm index 0 - 21
' MapTypeControl = true displays the map type control
' DispZoomControl = true displays the zoom control otherwise false
' ScaleControl = true displays the zoom control otherwise false
' ScaleControlPosition = position of the scale control TOP_LEFT, TOP_CENTER, TOP_RIGHT, LEFT_CENTER, RIGHT_CENTER, BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT
' DispMarkerCenter = true sets a marker on the center of the map
' MarkerLat = List of lat positions of the markers
' MarkerLong = List of long positions of the markers
' DipsMarkers = true displays the markers
' DispPolyline = true displays a polyline with the markers as vertices
' PolyLineColor = polyline color hexadecimal #ff0000 = red #00ff00 = green #0000ff = blue
' PolyLineOpacity = polyline opacity 0.0 transparent 1.0 full opaque
' PolyLineWidth = polyline width in pixels
Dim HtmlCode As String
Dim i, j As Int
HtmlCode = "<!DOCTYPE html><html><head><meta name='viewport' content='initial-scale=1.0, user-scalable=no' /><style type='text/css'> html { height: 100% } body { height: 100%; margin: 0px; padding: 0px }#map_canvas { height: 100% }</style><script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=true'></script><script type='text/javascript'> function initialize() {var latlng = new google.maps.LatLng(" & CenterLat & "," & CenterLong & "); var myOptions = { zoom: "&Zoom&", center: latlng, disableDefaultUI: true, zoomControl: "& DispZoomControl & ", scaleControl: "& DispScaleControl & ", scaleControlOptions: {position: google.maps.ControlPosition." & ScaleControlPosition & "}, mapTypeControl: "& MapTypeControl& ", mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions)"
' displays a marker on the map center
If DispMarkerCenter = True Then
HtmlCode = HtmlCode & "; var markerc = new google.maps.Marker({ position: new google.maps.LatLng(" & CenterLat & "," & CenterLong & "),map: map, title: '',clickable: false,icon: 'http://www.google.com/mapfiles/arrow.png' })"
End If
' displays markers on the map
If MarkerLat.Size>0 AND DispMarkers = True Then
j = MarkerLat.Size - 1
If j = 0 Then
HtmlCode = HtmlCode & "; var marker" & i & " = new google.maps.Marker({ position: new google.maps.LatLng(" & MarkerLat.Get(i) & "," & MarkerLong.Get(i) & "),map: map, title: 'Test" & i & "',clickable: true, draggable: true, icon: 'http://www.google.com/mapfiles/marker_red.png' })"
' HtmlCode = HtmlCode & "; google.maps.event.addListener(marker" & i & ", 'click', function() {alert('Marker1')} )"
Else If j = 1 Then
HtmlCode = HtmlCode & "; var marker" & i & " = new google.maps.Marker({ position: new google.maps.LatLng(" & MarkerLat.Get(i) & "," & MarkerLong.Get(i) & "),map: map, title: 'Test" & i & "',clickable: true, draggable: true, icon: 'http://www.google.com/mapfiles/marker_green.png' })"
' HtmlCode = HtmlCode & "; google.maps.event.addListener(marker" & i & ", 'click', function() {map.set_center(marker" & i & ")} )"
HtmlCode = HtmlCode & "; var marker" & i & " = new google.maps.Marker({ position: new google.maps.LatLng(" & MarkerLat.Get(i) & "," & MarkerLong.Get(i) & "),map: map, title: 'Test" & i & "',clickable: true, draggable: true, icon: 'http://www.google.com/mapfiles/marker.png' })"
' HtmlCode = HtmlCode & "; google.maps.event.addListener(marker" & i & ", 'click', function() {map.set_center(marker" & i & ")} )"
Else
HtmlCode = HtmlCode & "; var marker0 = new google.maps.Marker({ position: new google.maps.LatLng(" & MarkerLat.Get(i) & "," & MarkerLong.Get(i) & "),map: map, title: 'Test0',clickable: true, draggable: true, icon: 'http://www.google.com/mapfiles/marker_greenA.png' })"
' HtmlCode = HtmlCode & "; google.maps.event.addListener(marker0, 'click', function() {alert('Marker0')} )"
For i = 1 To j - 1 ' diplays the markers
HtmlCode = HtmlCode & "; var marker" & i & " = new google.maps.Marker({ position: new google.maps.LatLng(" & MarkerLat.Get(i) & "," & MarkerLong.Get(i) & "),map: map, title: 'Test" & i & "',clickable: true, draggable: true, icon: 'http://www.google.com/mapfiles/marker_orange" & Chr(i + 65) & ".png' })"
' HtmlCode = HtmlCode & "; google.maps.event.addListener(marker" & i & ", 'click', function() {map.set_center(marker" & i & ")} )"
Next
HtmlCode = HtmlCode & "; var marker" & (j) & " = new google.maps.Marker({ position: new google.maps.LatLng(" & MarkerLat.Get(j) & "," & MarkerLong.Get(j) & "),map: map, title: 'Test" & j & "',clickable: true, draggable: true, icon: 'http://www.google.com/mapfiles/marker" & Chr(j + 65) & ".png' })"
' HtmlCode = HtmlCode & "; google.maps.event.addListener(marker" & i & ", 'click', function() {map.set_center(marker" & i & ")} )"
End If
' displays a polyline between the markers
If DispPolyline = True AND j > 0 Then
HtmlCode = HtmlCode & "; var points = ["
HtmlCode = HtmlCode & " new google.maps.LatLng(" & MarkerLat.Get(0) & "," & MarkerLong.Get(0) & ")"
For i=1 To j
HtmlCode = HtmlCode & ", new google.maps.LatLng(" & MarkerLat.Get(i) & "," & MarkerLong.Get(i) & ")"
Next
HtmlCode = HtmlCode & "] "
HtmlCode = HtmlCode & "; var polyline = new google.maps.Polyline({path: points, strokeColor: '" & PolyLineColor & "', strokeOpacity: " & PolyLineOpacity & ", strokeWeight: " & PolyLineWidth & "})"
HtmlCode = HtmlCode & "; polyline.setMap(map)"
End If
End If
HtmlCode = HtmlCode & "; }</script></head><body onload='initialize()'> <div id='map_canvas' style='width:100%; height:100%'></div></body></html>"
If w=0 Then
WebView1.LoadHtml(HtmlCode)
Else
WebView2.LoadHtml(HtmlCode)
End If
End Sub
Sub Timer3_Tick
Timer3.Enabled = False
PosLat.Initialize
PosLong.Initialize
PosLat.clear
PosLong.clear
lat=Main.lblLat
lng=Main.lbllon
PosLat.Add(lat)
PosLong.Add(lng)
ShowMap(lat, lng, SeekBar1.Value, False, False, False, "TOP_LEFT", True, PosLat, PosLong, True, False, "#ff0000", 0.5, 3)
'Timer3.Enabled = True
End Sub
Sub WebViewExtras1_ProgressChanged(NewProgress As Int)
' NewProgress is Current page loading progress, represented by an integer between 0 and 100.
If NewProgress=100 Then
WebView2.Visible = False
WebView1.Visible = True
w=1
Timer3.Enabled = True
End If
End Sub
Sub WebViewExtras2_ProgressChanged(NewProgress As Int)
' NewProgress is Current page loading progress, represented by an integer between 0 and 100.
If NewProgress=100 Then
WebView1.Visible = False
WebView2.Visible = True
w=0
Timer3.Enabled = True
End If
End Sub