Android Tutorial Googlemaps V3 In A Webview

Hi Everyone,

Until the mapview becomes available, I have managed to "squeeze" the googlemaps V3 JS API into a webview for an app I am working on :sign0060:

The benefit of the JS map over a static map is complete scrolling etc.

To give back to the community here is the code. All the code does is generate the HTML & javscript code to generate the maps !

I will create a mod if anyone is interested.

You will need an activity with a webview. I have set my webview in code to 100%x, 100%y


B4X:
Dim MapWebView as Webview
Dim Lat as Float
Dim Long as Float
Dim HtmlCode as String

Lat = -34.397     'Replace these with your app data
Long = 150.644

activity.addnew(MapWebView,0,0,100%x,100%y)

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(" & Lat & "," & Long & ");    var myOptions = {      zoom: 16,      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(" & Lat & "," & Long & "),map: map,title: '',clickable: false,icon: '' });   }</script></head><body onload='initialize()'>  <div id='map_canvas' style='width:100%; height:100%'></div></body></html>"

webview1.LoadHtml(HTML_Code)

Neil
 

stanks

Active Member
Licensed User
Longtime User
how to center map on country not on lat/lon? if that is possible at all...

thanks
 
Last edited:

schimanski

Well-Known Member
Licensed User
Longtime User
Is it possibe to prevent the webview from scrolling? I use this method to show only a outline map and I want to show a static 'map-picture'...

Tanks for help...
 

DonManfred

Expert
Licensed User
Longtime User
Is it possibe to prevent the webview from scrolling? I use this method to show only a outline map and I want to show a static 'map-picture'...
You can place a transparent panel over the webview and then you use a blank paneltouch sub to earn the event (dont allowing clicking somewhere on the map")
 

Shay

Well-Known Member
Licensed User
Longtime User
I am using direction API to get directions by json response
I am sending the start_location lat,lng and end_location lat,lng to
MarkerLat, MarkerLong in the MAP
but with the polyline I am getting straight lines in the map (outside the actual roads)
How do I fix it?
Do I need to use the encoded polyline (how do I show it in the map)
and also how to show the overview_polyline
(I am using google map v3 webview example from here)
 

Attachments

  • Json.zip
    4.3 KB · Views: 279
  • Screenshot_2015-01-16-23-52-22.png
    Screenshot_2015-01-16-23-52-22.png
    351.3 KB · Views: 301

Shay

Well-Known Member
Licensed User
Longtime User
Fixed, I am using decodePoly function, and draw it on map
 
Top