我已经构建了一个搜索我的位置的应用程序。
这是代码
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(){}
工作正常。但是没有导航键。 任何人都可以告诉我如何激活它
答案 0 :(得分:2)
如果您尝试在屏幕上放置不同的平移控件(例如,谷歌地图上常见的四个方向图标),您可能需要查看此版本control tutorial以获取Google Maps Javascript的第2版API。
基本上,该链接描述了which controls automatically appear的情况。但是,如果您想强制控制到您的谷歌地图,您可以按如下方式执行:
function initialize() {
//assuming 'map' already exists...
//add a large pan / zoom control to the map
map.addControl(new GLargeMapControl());
}