2011-09-19 30 views
1

我已經建立了一個應用程序來搜索我的位置。如何啓用谷歌地圖控制器(右,右..等箭頭)

下面是它工作正常的代碼

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

如果你想在屏幕上放置不同的搖控器(例如谷歌地圖上常見的四個方向圖標),你可以看看Google地圖Javascript API版本2的這個control tutorial

基本上,該鏈接描述在什麼情況下which controls automatically appear。但是,如果你想強制控制到你的谷歌地圖,你可以這樣做:

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

我試着把這段代碼。沒有您使用的哪一個谷歌地圖API的版本中正常工作:( – Muhammed

+1

? – NT3RP

+0

V2 '' – Muhammed