gpt4 book ai didi

javascript - 如何启用谷歌地图 Controller (右,右..等箭头)

转载 作者:行者123 更新时间:2023-11-30 18:38:45 28 4
gpt4 key购买 nike

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

这是代码

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(){}

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

最佳答案

如果您尝试在屏幕上放置不同的平移控件(例如谷歌地图上常见的四个方向图标),您可能想看看这个 control tutorial适用于 Google Maps Javascript API 版本 2。

基本上,该链接描述了在什么情况下 which controls automatically appear .但是,如果你想强制控制你的谷歌地图,你可以按如下方式进行:

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

关于javascript - 如何启用谷歌地图 Controller (右,右..等箭头),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7474069/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com