An example showing how to use custom tiles with the Google Maps JS API.
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
var mapEl = document.querySelector('#map');
var map = new google.maps.Map(mapEl, {
center: new google.maps.LatLng(39.8282, -98.5795),
zoom: 5
});
TILE_URL
with your own, which should look (roughly) like: https://example.com/sample/{z}_{x}_{y}.jpg
.Create a new tile layer using this URL:
// Replace this with your URL.
var TILE_URL = 'https://example.com/sample/{z}_{x}_{y}.jpg';
// Name the layer anything you like.
var layerID = 'my_custom_layer';
// Create a new ImageMapType layer.
var layer = new google.maps.ImageMapType({
name: layerID,
getTileUrl: function(coord, zoom) {
console.log(coord);
var url = TILE_URL
.replace('{x}', coord.x)
.replace('{y}', coord.y)
.replace('{z}', zoom);
return url;
},
tileSize: new google.maps.Size(256, 256),
minZoom: 1,
maxZoom: 20
});
// Register the new layer, then activate it.
map.mapTypes.set(layerID, layer);
map.setMapTypeId(layerID);
A complete example is shown in index.html
.
Further documentation at Google Maps JS API: Image Map Types.
Sample code by Google, under the Apache 2.0 License.
Watercolor map tiles by Stamen Design, under CC-BY-3.0.
Updated missing url https://maps.googleapis.com/maps/api/js?callback=initMap&key=AIzaSyDaoLdV31Y5ls8ABBpuAQt9t8RzMDfOMiM to https://maps.googleapis.com/maps/api/js?callback=initmap&key=aizasydaoldv31y5ls8abbpuaqt9t8rzmdfomim
https://maps.googleapis.com/maps/api/js?callback=initMap&key=AIzaSyDaoLdV31Y5ls8ABBpuAQt9t8RzMDfOMiM