Search code examples
google-maps-api-3google-map-tiles-api

How to apply API key to Google Maps Tile server URL?


I want to use Google Maps Tile server URL inside an application.

I'm using the URL
https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga
and it is working fine. The problem is that I'm not sure how to use my Google Cloud API key for this URL.

I tried adding the API key at the end of the URL:
https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga&key=[MY_KEY]
but I don't see any activity on "Maps JavaScript API" in my Google cloud console. Meaning that the API Key is not being used.

Does this URL need an API Key?
It's working without the Key for now, but I'm afraid it may not work in the long run or it may be illegal to use it without the Key.


Solution

  • Ok, So I spend some time on this and found some solutions for directly using Map Tile Server URL (without any coding required). Here is a summary:

    Google Maps:

    • The URL https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga currently works, but it is illegal to use as it violates Google Maps TOS Section 3.2.4a https://cloud.google.com/maps-platform/terms/#3-license. because it doesn't use an API Key.
    • There was a service called Google Maps Tile API, but it has discontinued since September 2019 (the API key need to be whitelisted to be able to use this service, and they don't do it anymore since Sep).

    So it seems for now there is no easy and simple way to get Tile Server URL from Google Maps.

    Bing Maps:

    • The URL is in the form http://ecn.{subdomain}.tiles.virtualearth.net/tiles/r{quadkey}.jpeg?g=129 where quadkey is a compact representation of variables x, y and z. So doesn't work directly in applications that require URL's that have x,y,z variables.

    Azure Maps:

    • The URL is in the form https://atlas.microsoft.com/map/tile?subscription-key=***&api-version=2.0&tilesetId=microsoft.imagery&zoom={z}&x={x}&y={y}. For different settings see here. The shortcoming of this approach is that currently it cannot be set to show hybrid maps (satellite + street and city names).

    MapBox:

    • The URL is in the form https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/256/{z}/{x}/{y}?access_token=***. You can set the style of the map (currently set to satellite-streets-v11) by choosing the desired value from here and replacing in the URL.