我们将尝试同时运行新版本和旧版本,一个月后,老的版本就会被停用。
Maps团队将透明地更新API,包括增强它地性能,修复它的bugs。这些bugs修复工作只是为了提高性能和填补漏洞,但是我们可能会不经意地破坏一些AP­-I客户,请在Maps
API讨论组中报告这些情况。
地理编码,路径,等等
Google Maps
API还没有包含地理编码和路由服务,但网罗上有很多的免费的地理编码。
示例:
the basics
创建一副地图并将其中心定位在Palo Alto;
var map = new GMap(document.getElementById("map"));
map.centerAndZoom(new GPoint(-122.141944, 37.441944), 4);
map movement and animation
recenterOrPanToLatLng方法进行一个持续的漫游,如果经纬度范围不在当前的地图窗口中的话,另外它还可以进行一个离散的移动。
var map = new GMap(document.getElementById("map"));
map.centerAndZoom(new GPoint(-122.1419, 37.4419), 4);
window.setTimeout(function() {
map.recenterOrPanToLatLng(new GPoint(-122.1569, 37.4569));
}, 2000);
Adding Controls to the Map
你可以使用addControl方法往地图上添加控件。在这个例子中,我们添加了GSmallMapControl和GMapTypeControl,折使得我­-们能够缩放,漫游地图并在地图和卫星影像之间做切换。
var map = new GMap(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.centerAndZoom(new GPoint(-122.141944, 37.441944), 4);
Event Listeners
事件监听器在GEvent.addListener方法中注册。在这个例子中,在用户将地图移动或者拖动以后,我们会返回地图的中间的经纬度坐标。
var map = new GMap(document.getElementById("map"));
GEvent.addListener(map, "moveend", function() {
var center = map.getCenterLatLng();
var latLngStr = ‘(‘ + center.y + ‘, ‘ + center.x + ‘)‘;
document.getElementById("message").innerHTML = latLngStr;
});
map.centerAndZoom(new GPoint(-122.141944, 37.441944), 4);
打开一个消息窗口(opening an info window)
显示一个指向地图中间的"hello
world"信息窗口。信息窗口一般的会在标签上方被打开,但是他们也可以在地图的任何地方被打开。
var map = new GMap(document.getElementById("map"));
map.centerAndZoom(new GPoint(-122.141944, 37.441944), 4);
map.openInfoWindow(map.getCenterLatLng(),
document.createTextNode("Hello world"));
地图叠加(Map Overlays)
创建了十个随机的标记和一个随机的折线来展示map
overlays的用途
// Center the map on Palo Alto
var map = new GMap(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.centerAndZoom(new GPoint(-122.141944, 37.441944), 4);
// Add 10 random markers in the map viewport using the default icon
var bounds = map.getBoundsLatLng();
var width = bounds.maxX - bounds.minX;
var height = bounds.maxY - bounds.minY;
for (var i = 0; i < 10; i++) {
var point = new GPoint(bounds.minX + width * Math.random(),
bounds.minY + height * Math.random());
var marker = new GMarker(point);
map.addOverlay(marker);
}
// Add a polyline with 4 random points. Sort the points by longitude so
that
// the line does not intersect itself.
var points = [];
for (var i = 0; i < 5; i++) {
points.push(new GPoint(bounds.minX + width * Math.random(),
&n








