Android Question Google Maps API

mrossen

Active Member
Licensed User
Longtime User
Hi,

I realized that Goggle had changed the way the charge using the maps api. You now need to have a key from google to show google map.

I have a small app for test that recieve a sms with lat and lon and then make a pointer on google maps.

This dont work any more. The existing app shows a watermark with "google developer something", but if I try to compile a new app only a white screen appears.

Anyone know how to set this up on google and put the key in b4a code?

My code is like this

B4X:
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 String, MarkerLong As String, 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.graffrossen.dk/android/letsgo_arrow.png' })"
    End If
    
    HtmlCode = HtmlCode & "; }</script></head><body onload='initialize()'>  <div id='map_canvas' style='width:100%; height:100%'></div></body></html>"

    WebViewGoogle.LoadHtml(HtmlCode)
    
    'Log(HtmlCode)
    
    GetNearestStreet(CenterLat, CenterLong)
    
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Use the native map instead of a webmap.

Follow the GoogleMaps Tutorial. It shows how to use the Api KEy

You dont need any line of Javascript to use markers, lines, Polygones on a GoogleMap. Even not a Webview.
 
Last edited:
Upvote 0
Top