Google Maps API 进级:监听键盘鼠标事件 加载KML或者GEORSS文档
监听键盘鼠标事件
Google已经集成了各种基本事件的监听及动作。只需开启相应的功能即可。
var map = new GMap2(document.getElementById("map"));
map.enableScrollWheelZoom();
map.setCenter(new GLatLng(39.92, 116.46), 4);
var kh = new GKeyboardHandler(map);
利用GeoCoder地理编码查询信息
var map;
//地理编码查询地点经纬度
function locate(address)
{
var geocoder=new GClientGeocoder();
geocoder.getLatLng(address,function(point)
{
if(!point)
{
alert(address+" not found");
}
else
{
map.panTo(point);
var marker = new GMarker(point);
map.addOverlay(marker);
}
});
}
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
var geoPoint= new GLatLng(39.92, -116.46);
map.setCenter(geoPoint, 4);
GEvent.addListener(map, "click", function()
{
locate(prompt("请输入需要查询的地址", ""));
});
}
}
加载KML或者GEORSS文档
示例代码:
//加载KML或GeoRSS
function loadXML(url)
{
var gx = new GGeoXml(url);
map.addOverlay(gx);
}
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
var geoPoint= new GLatLng(40, 158.9);
map.setCenter(geoPoint, 2);
}
}