Internet explorer 使用COM open从V2转换为V3
我一直在以一种稍微不同寻常的方式使用v2mapsapi,因为我使用IE作为COM对象,并使用Document对象的Write方法将JS和HTML代码放入COM浏览器对象中 我必须使用这里的技巧来动态加载JS 我在下面粘贴了我的V3代码,但它不起作用。我不是一个JS专家,所以我肯定它有一些问题 任何指示都会得到通知 也许是loadjavascriptcss的把戏让事情停止了,但我有几次都没有成功 谢谢Internet explorer 使用COM open从V2转换为V3,internet-explorer,google-maps-api-3,com,Internet Explorer,Google Maps Api 3,Com,我一直在以一种稍微不同寻常的方式使用v2mapsapi,因为我使用IE作为COM对象,并使用Document对象的Write方法将JS和HTML代码放入COM浏览器对象中 我必须使用这里的技巧来动态加载JS 我在下面粘贴了我的V3代码,但它不起作用。我不是一个JS专家,所以我肯定它有一些问题 任何指示都会得到通知 也许是loadjavascriptcss的把戏让事情停止了,但我有几次都没有成功 谢谢 <!DOCTYPE html PUBLIC "-//W3C//DTD X
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps - Address Searcher</title>
<script type="text/javascript">
var oMap = null;
var oGeocoder = null;
var sAddress = null;
function loadjscssfile(filename, filetype){
if (filetype=="js"){ //if filename is a external JavaScript file
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", filename)
}
else if (filetype=="css"){ //if filename is an external CSS file
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref)
}
//
// Called after initialization, initializes the map and searches for the
// given address.
//
function map_callback() {
// Get the address from the query string
sAddress = window.location.search.substring(8).replace(/%20/g, " ");
// Create map object
oMap = new google.maps.Map(document.getElementById("map_canvas"));
// Create a Geocoder and let it try to translate the address into a geographic position
oGeocoder = new google.maps.Geocoder();
oGeocoder.geocode({ 'address': "Address Line 1,Address Line 2,BIRMINGHAM,West Midlands,B26 3EX"}, function(results, status) {
if (status==google.maps.GeocoderStatus.OK) {
oMap.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: oMap,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>
</head>
<body onload="loadjscssfile('http://maps.googleapis.com/maps/api/js?v=3&callback=map_callback&sensor=false&key=AIzaSyCtZmbJtVVerKBh4L-iZCuDhG9OWIRs7x4&randomelementtopreventbrowsercache=5362664', 'js')" style="margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px;" oncontextmenu="return false;">
<span id="address_not_found" style="display:none">Address not found!</span>
<div id="map_canvas" style="position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;"></div>
</body>
</html>
谷歌地图-地址搜索器
var-oMap=null;
var-oGeocoder=null;
var sAddress=null;
函数loadjscssfile(文件名、文件类型){
if(filetype==“js”){//如果文件名是外部JavaScript文件
var fileref=document.createElement('脚本')
fileref.setAttribute(“类型”、“文本/javascript”)
fileref.setAttribute(“src”,文件名)
}
else if(filetype==“css”){//如果文件名是外部css文件
var fileref=document.createElement(“链接”)
fileref.setAttribute(“rel”、“样式表”)
fileref.setAttribute(“类型”、“文本/css”)
fileref.setAttribute(“href”,文件名)
}
if(fileref的类型!=“未定义”)
document.getElementsByTagName(“head”)[0]。appendChild(fileref)
}
//
//初始化后调用,初始化映射并搜索
//给定地址。
//
函数映射_回调(){
//从查询字符串中获取地址
sAddress=window.location.search.substring(8).替换(/%20/g,“”);
//创建地图对象
oMap=new google.maps.Map(document.getElementById(“Map_canvas”);
//创建一个地理编码器,让它尝试将地址转换为地理位置
oGeocoder=new google.maps.Geocoder();
地理代码({‘地址’:“地址行1,地址行2,伯明翰,西米德兰,B26 3EX”},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
oMap.setCenter(结果[0].geometry.location);
var marker=new google.maps.marker({
地图:oMap,
位置:结果[0]。几何体。位置
});
}否则{
警报(“地理编码因以下原因未成功:“+状态”);
}
});
}
找不到地址!
什么设置地图div的大小?它将不显示任何内容。代码的这一部分没有改变。我只想让它填满整个浏览器窗口。我认为moemt的问题在于,map_回调永远不会实际执行如果您想要百分比大小的映射,则需要为映射的每个容器设置一个百分比大小。谢谢你的提示。我加入了100%,但没有区别。我现在在第0行char 0上收到一个脚本错误,因此某些代码必须尝试在某个地方运行!好吧,我有进展了。这可能是因为缺少缩放级别、地图类型和需要的%20地址+