Google maps 谷歌地图标记,添加的方向代码不显示
我似乎很难在我创建的地图上添加一个标记,我就是想不出哪里出了问题 地图已经很好地添加到了网站上,我甚至有了方向代码,正好显示了标记 我想要的是一个初始标记,以显示学校所在的位置,在本例中,在单击时有一个信息框来显示地址,但无论我如何尝试,我似乎都无法让它显示出来 我的代码如下所示:-Google maps 谷歌地图标记,添加的方向代码不显示,google-maps,google-maps-markers,Google Maps,Google Maps Markers,我似乎很难在我创建的地图上添加一个标记,我就是想不出哪里出了问题 地图已经很好地添加到了网站上,我甚至有了方向代码,正好显示了标记 我想要的是一个初始标记,以显示学校所在的位置,在本例中,在单击时有一个信息框来显示地址,但无论我如何尝试,我似乎都无法让它显示出来 我的代码如下所示:- <div id="map_canvas" style="width:100%; height:392px;float:left;"></div> <div id="directio
<div id="map_canvas" style="width:100%; height:392px;float:left;"></div>
<div id="directionsPanel" style="float:left;max-width:395px; overflow:scroll;overflow-x: hidden;"></div>
<script>
//define one global Object
var myMap = {}
//init
function initialize(){
//set up map options
var mapOptions = {
center: new google.maps.LatLng(53.964304,-2.028522),
zoom: 15,
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
myMap.map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
myMap.directionsService = new google.maps.DirectionsService();
myMap.directionsDisplay = new google.maps.DirectionsRenderer();
myMap.directionsDisplay.setMap(myMap.map);
myMap.directionsDisplay.setPanel(document.getElementById("directionsPanel"));
}//end init
function createMarker(point, title, content, map) {
var marker = new google.maps.Marker({
position: point,
map: map,
title: title
});
var infowindow = new google.maps.InfoWindow({
content: content
});
google.maps.event.addListener(marker, 'click', function() {
if(curr_infw) { curr_infw.close();} // We check to see if there is an info window stored in curr_infw, if there is, we use .close() to hide the window
curr_infw = infowindow; // Now we put our new info window in to the curr_infw variable
infowindow.open(map, marker); // Now we open the window
});
return marker;
}
//directions
var calcRoute = function() {
var start = document.getElementById("start").value,
end = document.getElementById("end").value,
request = {
origin:start,
destination:end,
durationInTraffic :true,
transitOptions: {
departureTime: new Date()
},
provideRouteAlternatives : true,
travelMode: document.getElementById("travelmode").value
};
myMap.directionsService.route(request, function(result, status) {
if(status == google.maps.DirectionsStatus.OK) {
myMap.directionsDisplay.setDirections(result);
}else{
alert("something went wrong!");
}
});
}
//script loader
var loadScript = function() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?key=AIzaSyDZsY0Xbo137bDtb8wmefTogdGl82QM85s&sensor=false&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;
//定义一个全局对象
var myMap={}
//初始化
函数初始化(){
//设置地图选项
变量映射选项={
中心:新google.maps.LatLng(53.964304,-2.028522),
缩放:15,
滚轮:错误,
mapTypeId:google.maps.mapTypeId.ROADMAP,
};
myMap.map=new google.maps.map(document.getElementById(“map_canvas”),mapOptions);
myMap.directionsService=新建google.maps.directionsService();
myMap.directionsDisplay=新建google.maps.DirectionsRenderer();
myMap.directionsDisplay.setMap(myMap.map);
myMap.directionsDisplay.setPanel(document.getElementById(“directionsPanel”);
}//结束初始化
函数createMarker(点、标题、内容、地图){
var marker=new google.maps.marker({
位置:点,,
地图:地图,
标题:标题
});
var infowindow=new google.maps.infowindow({
内容:内容
});
google.maps.event.addListener(标记'click',函数(){
如果(curr_infw){curr_infw.close();}//我们检查curr_infw中是否存储了信息窗口,如果有,我们使用.close()隐藏窗口
curr\u infw=infowindow;//现在我们将新的info窗口放入curr\u infw变量中
infowindow.open(map,marker);//现在我们打开窗口
});
返回标记;
}
//方向
var calcRoute=函数(){
var start=document.getElementById(“start”).value,
end=document.getElementById(“end”).value,
请求={
来源:start,
目的地:完,
持续时间:对,
过渡:{
出发时间:新日期()
},
ProviderRouteAlternatives:正确,
travelMode:document.getElementById(“travelMode”).value
};
myMap.directionsService.route(请求、函数(结果、状态){
if(status==google.maps.directionstatus.OK){
myMap.directionsDisplay.setDirections(结果);
}否则{
警惕(“出了问题!”);
}
});
}
//脚本加载器
var loadScript=函数(){
var script=document.createElement(“脚本”);
script.type=“text/javascript”;
script.src=”http://maps.googleapis.com/maps/api/js?key=AIzaSyDZsY0Xbo137bDtb8wmefTogdGl82QM85s&sensor=false&callback=initialize";
document.body.appendChild(脚本);
}
window.onload=loadScript;
在我拔完所有的头发变成秃头之前,对这些家伙的任何帮助都将不胜感激
杰森