Android Question Does GPSExample need Google API key to use Google Maps?

Didier9

Well-Known Member
Licensed User
Longtime User
Looking at the code from the GPS Example, it does not look like there is any need for an API key to use this code. Are there any limitations in using Google services that way?
 

DonManfred

Expert
Licensed User
Longtime User
GPS and Google Play Services are two parts...
You do not need a Api key for GPS
You do not need Play Services for GPS
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
GPS and Google Play Services are two parts...
You do not need a Api key for GPS
You do not need Play Services for GPS

I realize my question was not clear.
The GPSExample code uses Google Maps. The question is "do I need an API key to use Google Maps the way it is used in the GPSExample code?"
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
The GPS Example from the GPS Tutorial does not use Google Maps!

Yes it does. The extract below is from the MapDisp() function:

B4X:
http://maps.google.com/maps/api/

Clarification: this comes from the only GPSExample I know of, the one from klaus, that is available via the forum. I do not know about the GPS Tutorial.

The GPSExample works without an API key.

I saw that and that was the point of my question. How does it work? Doesn't Google require an API key to access their services via an app?
This is from the Googe API web page:

To use the Google Maps JavaScript API, you must register your app project on the Google API Console and get a Google API key which you can add to your app.

If I create an app with this code and (wild dream) there are a lot of users, will Google shut it down?
Or is the WebView request looking like a normal web browser request and Google does not care or know the request actually comes from an app?

I a curious about the scalability of such an approach for an app that may see distribution.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Or is the WebView request looking like a normal web browser request and Google does not care or know the request actually comes from an app?
I don't know, I have never published an app on Play Store.
When you use GoogleMaps with a browser you don't need any key.
And the WebView is similar for me, but, who knows with Google.
The GPSExample uses a WebView because when I developped it the GoogleMaps library didn't exist.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User

No need to use upper case, I can read lower case just fine with my progressive lenses :)

Different GPSExample...

You must have missed my post. This is the code (from Klaus, who correctly understood my question and responded) I am referring to:

B4X:
Sub MapDisp(CenterLat As Float, CenterLng As Float, MapDraggable As Boolean, Zoom As Int, MapTypeControl As Boolean, _
        MapTypeControlID As String, DispZoomControl As Boolean, ZoomControlPosition As String, ZoomControlStyle As String, _
        DispScaleControl As Boolean, ScaleControlPosition As String, DispMarkerCenter As Boolean, MarkerPos As List, _
        DispMarkers As Boolean, MarkersClickable As Boolean, MarkersDragable As Boolean, DispPolyline As Boolean, _
        PolyLineColor As String, PolyLineOpacity As Float, PolyLineWidth As Int)
' Displays a Google map in a WebView with following parameters
' Thanks go to  for his WebViewExtra library allowing to add event routines
    ' CenterLat        = latitude of map center in degrees
    ' CenterLng       = longitude of map center in degrees
    ' Zoom             = zomm index   0 - 21
    ' MapTypeControl   = true displays the map type control
    ' MapTypeControlID   = either ROADMAP, TERRAIN, SATELLITE or HYBRID
    ' DispZoomControl  = true displays the zoom control otherwise false
    ' ZoomControlPosition  = position of the scale control TOP_LEFT, TOP_CENTER, TOP_RIGHT, LEFT_CENTER, RIGHT_CENTER, BOTTOM_LEFT,
        'BOTTOM_CENTER, BOTTOM_RIGHT
    ' ZoomControlStyle  = style of the scale control DEFAULT, SMALL or LARGE
    ' 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
    ' MarkerPos            = List of GPS Locations of the markers
    ' DipsMarkers           = true displays the markers
    ' MarkersClickable = the markers are clickable, doesn't work yet with WebView
    ' MarkersDragable  = the markers are dragable, doesn't give the new postition yet with WebView
    ' 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
    
     Private HtmlCode As String
    Private i, j, n As Int
    Private Pos As GPSLocation
    HtmlCode = "<!DOCTYPE html><html><head><meta name='viewport' content='initial-scale=1.0, user-scalable=no' /><style type='text/css'>  "
    HtmlCode = HtmlCode & "html { height: 100% }  body { height: 100%; margin: 0px; padding: 0px }#map_canvas "
    HtmlCode = HtmlCode & "{ height: 100% }</style><script Type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=true'>"

Look at the last line of the code window above, where it says

B4X:
src='http://maps.google.com/maps/api/js

Maybe you are referencing another project that I am not aware of.
My question specifically references the GPSExample app written by Klaus.

By the way, this is an excellent example, very complete and with useful comments in the code. I was able to extract the functionality I needed and I have integrated it into my app. Thanks Klaus!
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
I don't know, I have never published an app on Play Store.
When you use GoogleMaps with a browser you don't need any key.
And the WebView is similar for me, but, who knows with Google.
The GPSExample uses a WebView because when I developped it the GoogleMaps library didn't exist.

This example looks like it does what I need so I am not sure yet if I would need to use the library. I would rather not if I can avoid having to use an API key, not that it's complicated but it's just another thing...

On my personal web site, I had a demo web page I did for a prospective client that displayed a google map with some information on it (http://www.ko4bb.com/AjaxDemo/x-web.html)
That code originally worked (several years ago) but later Google stopped servicing the requests and I had to take a Google API key for that code to work again, so that is what prompted the question.

It looks like it would be safer to use a key though. It would reduce the risk of Google shutting down that service without notice.

Thanks Klaus.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
As far as I know Google Maps recognises the App from it's package name and collects statistic using this feature.
Do you know if that applies to the webview as well?
I am curious what browser is reported when the webview fetches a web page. I should be able to find out looking at my logs.
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
Since Google has no control on web applicatives They need a key. Some year ago I had to buy a certain number of map imptessions since my web application showed a lots. If you showed more than (2000?) Maps a day the free account could block.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
Since Google has no control on web applicatives They need a key. Some year ago I had to buy a certain number of map imptessions since my web application showed a lots. If you showed more than (2000?) Maps a day the free account could block.

Thank you, that rings a bell.
 
Upvote 0
Top