# Google Map in Notebooks?

GoogleMaps are implemented as HTML and Javascript code which can be viewed by a web browser. Is it possible to load this map into the Mathematica notebook, which obviously means for example that

<script src="http://maps.google.com/maps?file=api&amp;v=2.s&amp;key="
type="text/javascript">
</script>
<script src="/Users/meinmacbookpro/Desktop/Messprojekte/gps.js"
type="text/javascript">
</script>


should be implemented somehow into the Mathematica code?

All we need to create an interactive Google Map in the notebook is access to the individual tiles - and there is a relatively simple naming scheme for those tiles. The most basic form of a tile URL looks like: http://mt0.google.com/vt/x=xi&y=yi&z=i, where $$0\leq xi,yi < 2^i$$. For example, at zoom level z=0, there is one tile representing the whole earth: At zoom level 1, there are 4 tiles that cover most of the earth: With a little understanding of the Mercator projection, it's not hard to translate from lat/lng values to tile indices:

{alng,blng} = First[{a,b} /. Solve[
{a*(-180)+b==0,a(180)+b==1},{a,b}]];
lngToIndex[lng_, zoom_] := Floor[(alng*lng+blng)2^zoom];
mercator[lat_] = Log[Abs[Sec[lat*Degree]+Tan[lat*Degree]]];
{alat,blat} = First[{a,b} /. Solve[{a*mercator[85.0511287798066]+b==0,
a*mercator[-85.0511287798066]+b==1},{a,b}]];
latToIndex[lat_, zoom_] := Floor[(alat*mercator[lat]+blat)2^zoom];
indicesToTileURL[x_Integer, y_Integer, zoom_Integer] :=
"http://mt0.google.com/vt/x=" <> ToString[x] <> "&y=" <>
ToString[y] <> "&z=" <> ToString[zoom]


Now, suppose I'd like to compute the URL of a tile in my neighborhood.

{lat0,lng0} = CityData["Asheville", "Coordinates"];
x0=lngToIndex[lng0,10];
y0=latToIndex[lat0,10];
indicesToTileURL[x0,y0,10]



We can put this all together to set up an interactive zoomer.

Manipulate[
With[{x0=lngToIndex[lng0,zoom],y0=latToIndex[lat0,zoom]},
Grid[{
{Import[indicesToTileURL[x0-1,y0-1,zoom]],
Import[indicesToTileURL[x0,y0-1,zoom]],
Import[indicesToTileURL[x0+1,y0-1,zoom]]},
{Import[indicesToTileURL[x0-1,y0,zoom]],
Import[indicesToTileURL[x0,y0,zoom]],
Import[indicesToTileURL[x0+1,y0,zoom]]},
{Import[indicesToTileURL[x0-1,y0+1,zoom]],
Import[indicesToTileURL[x0,y0+1,zoom]],
Import[indicesToTileURL[x0+1,y0+1,zoom]]}
}, Spacings -> {0,0}]
],{{zoom,13},Range[2,18]}] This is really just proof of concept at this point. There's quite a lot more that could be done. You could use an EventHandler to allow dragging and panning and add other controls as well. You'd need some error handling to deal with scrolling out of range. You could also interface other map servers.