itowns icon indicating copy to clipboard operation
itowns copied to clipboard

Tiles from Google maps

Open Gekk0r opened this issue 4 years ago • 5 comments

Do you already implemented a way to load Google maps tiles?

As I understood , in iTowns implementation you already using bbox, zoom, width and height to retrive the png instead Google API needs lat, long (center of the bbox), zoom, API key, width and height...

What do you think? :)

Gekk0r avatar Jul 18 '20 20:07 Gekk0r

I think I saw an issue about that, but can't seem to find it !

From what I looked, Google doesn't offer a way to query tiles only, you need to use their own Maps implementation. Could you link the documentation if it is the case so I can help ?

The classic map has a weird URL that I don't know how it is constructed (https://www.google.fr/maps/vt/pb=!1m4!1m3!1i15!2i16602!3i11278!2m3!1e0!2sm!3i520236696!3m7!2sen!5e1105!12m4!1e68!2m2!1sset!2sRoadmap!4e1!5m4!1e4!8m2!1e0!1e1!6m7!1e12!2i2!26m1!4b1!39b1!44e1!50e0!23i1358902 for example), while the satellite view may be accessible, as it uses a x, y and a z. You may then use TMSSource and ColorLayer in iTowns to display it. See this example or this one to see how to use a TMSSource.

I found some layers that you can try, with the following url, but I am not really sure it can be use without an API key

  • Google Maps: https://mt1.google.com/vt/lyrs=r&x=${x}&y=${y}&z=${z}
  • Google Satellite: http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x=${x}&y=${y}&z=${z}
  • Google Satellite Hybrid: https://mt1.google.com/vt/lyrs=y&x=${x}&y=${y}&z=${z}
  • Google Terrain: https://mt1.google.com/vt/lyrs=t&x=${x}&y=${y}&z=${z}
  • Google Roads: https://mt1.google.com/vt/lyrs=h&x=${x}&y=${y}&z=${z}

zarov avatar Jul 20 '20 06:07 zarov

Actually, something like http://mt1.google.com/vt/lyrs=y&x=1325&y=3133&z=13 works without any API key, I tried to use it with TMSSource that works but sometimes return error Too many requests.

Whatever, I tried to implement something (just as experiment while fetching the texture in itown.js) that fetch data using the follow request https://maps.googleapis.com/maps/api/staticmap?center=" + bbox_center.x + "," + bbox_center.y + "&zoom=9&size=256x256&maptype=satellite&key=MY_APY_KEY".

My solution works (fetch the images correctly) but I don't know the properly way to change the z.

Gekk0r avatar Jul 20 '20 08:07 Gekk0r

The Too many requests doesn't surprise me, as there is not API key to specify, so this may be a limited stream.

You could compute the zoom, knowing the size of the root bbox (aka the earth). Something like Math.round(bbox_root.x / bbox_local * some_factor_to_determine) ?

From what I saw, using staticmap may not be the best solution here, as it doesn't seem adapted for this usage ?

zarov avatar Jul 20 '20 09:07 zarov

You could compute the zoom, knowing the size of the root bbox (aka the earth). Something like Math.round(bbox_root.x / bbox_local * some_factor_to_determine) ?

Thank you for the tip, I will try it..

From what I saw, using staticmap may not be the best solution here, as it doesn't seem adapted for this usage ?

Agree, but it seems the only "easy" way to use google layer with API key.

BTW: I'm already satisfied with TMSSource :).

Gekk0r avatar Jul 20 '20 09:07 Gekk0r

Agree, but it seems the only "easy" way to use google layer with API key.

Yeah, they really don't want people using other library than their ;)

Let me know how it goes !

zarov avatar Jul 20 '20 09:07 zarov