Android Question Google map in WebView

khwarizmi

Active Member
Licensed User
Longtime User
Hello all

I used this code to display a google map in a WebView:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
 Dim MapWebView As WebView
End Sub
 
Sub Activity_Create(FirstTime As Boolean)
 MapWebView.Initialize("")
 Activity.AddView(MapWebView,0,0,100%x,100%y)
 ShowMap(46.138, 7.118, 15)
End Sub

Sub ShowMap(Latitude As Float, Longitude As Float, Zoom As Int)
 Dim HtmlCode As String
 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(" & Latitude & "," & Longitude & "); var myOptions = { zoom: "&Zoom&", center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); var marker0 = new google.maps.Marker({ position: new google.maps.LatLng(" & Latitude & "," & Longitude & "),map: map,title: '',clickable: false,icon: '' }); }</script></head><body onload='initialize()'> <div id='map_canvas' style='width:100%; height:100%'></div></body></html>"
 MapWebView.LoadHtml(HtmlCode)
End Sub

* How can I get the Latitude and the Longitude of any point when I click on it ?
* How can I add a marker in a point if I know the Latitude and the Longitude of it ?
 

khwarizmi

Active Member
Licensed User
Longtime User
Thanks klaus ..
I found the answer to the second question in your program , How can I add a marker in a point if I know the Latitude and the Longitude, Now I want to click on a point and get the Latitude and the Longitude .
 
Upvote 0
Top