Thursday, October 22, 2009

Google maps tiles in a MapViewer app

Earlier this year I posted an article on how to display MapViewer generated tiles in a Google Maps application. In this post I will discuss how to display Google Maps tiles in a MapViewer/Oracle Maps application.

Starting with MapViewer 11g Release 1, a built-in Google Maps tile layer class has been added to the MapViewer's JavaScript API. It is called MVGoogleTileLayer. Unfortunately it is not officially documented for 11g Release 1 (but will be in the upcoming patch and future releases).

This API class is a thin wrapper of the official Google Maps API, and as such you will need to get your own Google Maps key for your application.

The basic steps for displaying Google Maps in your Oracle Maps application are:

Step 1. Import the Google Maps JavaScript library

<script src="[your-Google-Maps-API-key]"

Again you will need to get your own Google Maps key from Google and set it in the above script tag.

Step 2. Add a Google Maps tile layer to the MVMapView object

mapview = new MVMapView(document.getElementById("map"), baseURL);
baseMap = new MVGoogleTileLayer() ;

That's all it takes to display a basic Google Maps map in your MapViewer application.

You can also change the type of map you get from Google Maps. Here is an example:

var mapType = G_HYBRID_MAP;
basemap.setMapType(mapType) ;

Where basemap is a MVGoogleTileLayer instance. Note that G_HYBRID_MAP is a constant defined by the imported Google Maps API library and represents a hybrid Google Maps type. The full description for this method is:

This method sets the type of the map, which can be one of the following predefined Google Map types, G_NORMAL_MAP, G_SATELLITE_MAP, G_HYBRID_MAP and G_PHYSICAL_MAP.

The only other method defined on the MVGoogleTileLayer class is getMapType(), which returns the current map type of the Google Maps being displayed.

Finally, as part of your application cleanup, please call Google Maps' clean-up method GUnload() (such as in the HTML page's unload event listener).


jomara said...

Can I bring in data which is in State Plane coordinates Nad 83 to a google layer? When I try this I am getting Mapviewer-05523: Cannot process response from Mapviewer server. failure on initializtion of coordinate transformation.

LJ said...

Your Spatial database may not have the required world mercator coordinate system (SRID 54004 or 3785) to perform the necessary transformation. If that's the case (after checking your DB's mdsys.cs_srs table), you can install these CS by following the instructions in my earlier blog (

bertram.hof said...


I've tried your example and showing a map works.
Displaying a HYBRID version of by using your suggested setMapType(G_HYBRID_MAP) doesn't.
In the google-api documentation of the API it says that you need to tell the map whichs modes are allowed within the map. Can it have anything to do with the way the MVGoogleTiles methode works?.

Thanks in advance,

Bertram Hof

Ji Yang said...

11gR1 has some issue with setting the map to a non-default type before the map is initialized. But there should be problem in changing the map type after the map has been displayed.

This issue will be fixed in next release.

bertram.hof said...


I've got it working now. My implementation is using apex as a framewqork. Setting the mapType works not within the initial showmap procedure. After displaying the initial map. Next events can be used to change the type to whatever you want.

Next issue however i have is displaying my own theme over a mapping. My geometry is based on 28992 instead of 3785. Using the transform of spatial from 28992 to 3785 i'm getting a difference in the Netherlands of appr. 30 km. I've heard this issue is known and is solved in the 11gr2 release. Do you have however a solution for this in a 10g or 11gr1 situation?.

Thanks in advantage

Jayant said...

It'll work with 10gr2 ( or later) and 11gR1. However you have to explicitly define a rule that says ignore the datum shift (i.e. use spherical math and not ellipsoidal) when transforming to and from 3785. In 11gr2 there's a named use case called 'USE_SPHERICAL' which does this and so there's no need for an explicit rule.

bertram.hof said...

I,m not so familiar with Oracle Spatial. Can you show me the way to doe that or do you have a place where I can find an example.

Nguyen Binh said...

How to use MVGoogleTileLayer
Google Maps JavaScript API v3 ?

Thank you very much

faq said...


could you please let me know how to use google maps in mapviewer through java not though oracle maps(java script).