如何启用谷歌地图控制器(对,对.等箭)

How to enable Google map controllers (right,right..etc arrows)

本文关键字:何启用 等箭 控制器 谷歌地图 启用      更新时间:2023-09-26

我已经建立了一个应用程序来搜索我的位置。

代码

var map;
var gdir;
var geocoder = null;
var addressMarker;   
function initialize() {
    if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
        map.setCenter(new GLatLng(51.519853,-0.122566), 14)
        var point = new GLatLng(51.519853,-0.122566); //CHANGE THESE COORDINATES
        map.addOverlay(new GMarker(point));
        map.openInfoWindow(map.getCenter(),html)
    }
}  
function setDirections(fromAddress) {
    gdir.load("from: " + fromAddress + " to: 51.519741,-0.122596 ");
}  
function handleErrors(){
    if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS) {
        alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.'nError code: " + gdir.getStatus().code);
    } else if (gdir.getStatus().code == G_GEO_SERVER_ERROR) {
       alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.'n Error code: " + gdir.getStatus().code);
    } else if (gdir.getStatus().code == G_GEO_MISSING_QUERY) {
       alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.'n Error code: " + gdir.getStatus().code);           
    } else if (gdir.getStatus().code == G_GEO_BAD_KEY) {
       alert("The given key is either invalid or does not match the domain for which it was given. 'n Error code: " + gdir.getStatus().code);    
    } else if (gdir.getStatus().code == G_GEO_BAD_REQUEST) {
       alert("A directions request could not be successfully parsed.'n Error code: " + gdir.getStatus().code);    
    } else {
       alert("An unknown error occurred.");
    }
}
function onGDirectionsLoad(){} 

它工作正常。但是没有导航键。谁能告诉我怎么激活它呢

如果你想在屏幕上放置不同的平移控件(例如,在谷歌地图上常见的四个方向图标),你可能想看看这个版本2的谷歌地图Javascript API控件教程。

基本上,该链接描述了在什么情况下哪些控件会自动出现。但是,如果您想强制控件进入您的google地图,您可以这样做:

function initialize() {
    //assuming 'map' already exists...
    //add a large pan / zoom control to the map
    map.addControl(new GLargeMapControl());
}