I wonder know if the last version of Openlayers (v4.0.1) supports Google Maps as a Tile Layer. I can't find any documention about this. If Openlayers doesn't support Google Maps, someone could tell me if there is any way to do this.
Asked
Active
Viewed 6,554 times
2 Answers
8
OpenLayers has a written consent for using the api, which they used for OL2 and OL3. The support for it was stopped because of recurring issues with said api.
We are not allowed to use the tiles directly, the answer is not legal.
However, you may use Google's Map api and write your own OL source implementation with it or use an existing extension like ol3-google-maps
More information can be found here: https://github.com/openlayers/openlayers/issues/2205

dube
- 4,898
- 2
- 23
- 41
5
For the Google's satellite data you can go with TileImage source, specifying pattern url's:
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.TileImage({url: 'http://khm0.googleapis.com/kh?v=717&hl=pl&&x={x}&y={y}&z={z}'})
})
],
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([19.2, 52]),
zoom: 6
})
});
EDIT: For the Google's plain map data you can go with TileImage source, specifying pattern url's for the parts of pb argument:
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.TileImage({url: 'http://maps.google.com/maps/vt?pb=!1m5!1m4!1i{z}!2i{x}!3i{y}!4i256!2m3!1e0!2sm!3i375060738!3m9!2spl!3sUS!5e18!12m1!1e47!12m3!1e37!2m1!1ssmartmaps!4e0'})
})
],
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([19.2, 52]),
zoom: 6
})
});

Michał Okulewicz
- 159
- 2
- 7
-
1or it is even easier with the address given in the answer for OL3: http://stackoverflow.com/a/33993878/6068293 – Michał Okulewicz Mar 11 '17 at 22:17
-
8Directly accessing the tiles like that might be a violation of Google's terms of service. https://developers.google.com/maps/terms section 10.1.a – Rob Jun 19 '17 at 16:49