How can I use Google map data in the Google Maps API?
This is almost the most common question I have heard about Google Maps APIs. As we all know, Google Maps does not have a detailed map of China. In China, we only have a unique Google map website that provides a detailed map of China. The reason for this situation has not been officially explained by Google and Google, but we can probably guess it by ourselves. We will not say much about it.
Question: How can we use a detailed map of China in the Google Maps API? Previously, I always answered this question. Google Maps provides APIs that are compatible with the Google Maps API syntax. The only problem is that they are not stable. This method is actually not good, because you need to consider how to switch between two different objects in the code, the code logic will become very complicated.
However, because Google Maps's current scaling level and switching mode are already exactly the same as Google Maps. Therefore, we have a very good solution, that is, to directly use the map block of Google Maps to build a custom map type of Google Maps API.
The following is an example of using Google map in the Google Maps API from Anthony Wong (four options are displayed for the map type, and the fourth ditu is the Google Map button ):
The core code is:
var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90, -180),
new GLatLng(90, 180)),
0, "Map data: В2007 Mapabc.com");
var copyrightCollection = new GCopyrightCollection("В2007 Google - ");
copyrightCollection.addCopyright(copyright);
var dituTileLayer = new GTileLayer(copyrightCollection, 1, 17);
dituTileLayer.getTileUrl = function(tile, zoom) {
return "http://mapgoogle.mapabc.com/googlechina/maptile?v=w2.52&x=" +
tile.x + "&y=" + tile.y + "&zoom=" + (17-zoom);
};
// Using a map type:
var dituMapType = new GMapType([dituTileLayer],
new GMercatorProjection(23), "Ditu", { shortName: "ditu", alt: "Show maps from Google China" });
map.addMapType(dituMapType);