google map api在ie6中:缺少对象的解决方案
2008-12-23 11:15
609 查看
用过google map api的人都应该会注意到,示例的js脚本在FF,opera,...(非ie6的浏览器)都正常.在ie6下会报错:
缺少对象
错误的行号一般都指向GMap2对象创建的行上
解决方案有两种:
1.在meta中指定charset=utf-8,原因大家可以去google中勾一下
2.如果应用中的charset都是非utf-8哪怎么办呢?总不能为了一粒米丢掉所有玉米.方案如下
要在网站中使用map api就要引用一个js文件,我们可以在这想办法,在script的属性中也有一个charset属性,添加它
<script ... charset="utf-8"></script>
下面是一些示例
用的map key为:t6new.cn的
默认示例(ie下会提示缺少对象)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAy_92lh6L5xhcKXiWFze7ahSeyyn5-963h60-vJRKrf4xaRdBuBTmF2UsZnFk8o95hGt2T99GRoVPiA"
type="text/javascript"></script>
<title>google map demo</title>
<script type="text/javascript">
//<![CDATA[
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.5429, 121.3776), 13);
geocoder = new GClientGeocoder();
}
}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
}
//]]>
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<input type="text" name="address" size="50" value="烟台市西盛街28号第一大道" onblur="showAddress(this.value);" />
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
</html>
meta示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAy_92lh6L5xhcKXiWFze7ahSeyyn5-963h60-vJRKrf4xaRdBuBTmF2UsZnFk8o95hGt2T99GRoVPiA"
type="text/javascript"></script>
<title>google map demo</title>
<script type="text/javascript">
//<![CDATA[
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.5429, 121.3776), 13);
geocoder = new GClientGeocoder();
}
}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
}
//]]>
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<input type="text" name="address" size="50" value="烟台市西盛街28号第一大道" onblur="showAddress(this.value);" />
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
</html>
script属性charset示例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAy_92lh6L5xhcKXiWFze7ahSeyyn5-963h60-vJRKrf4xaRdBuBTmF2UsZnFk8o95hGt2T99GRoVPiA"
type="text/javascript" charset="utf-8"></script>
<title>google map demo</title>
<script type="text/javascript">
//<![CDATA[
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.5429, 121.3776), 13);
geocoder = new GClientGeocoder();
}
}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
}
//]]>
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<input type="text" name="address" size="50" value="烟台市西盛街28号第一大道" onblur="showAddress(this.value);" />
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
</html>
在小站上的示例是基于script的charset属性: http://www.t6new.cn/feature/maptest.html
缺少对象
错误的行号一般都指向GMap2对象创建的行上
解决方案有两种:
1.在meta中指定charset=utf-8,原因大家可以去google中勾一下
2.如果应用中的charset都是非utf-8哪怎么办呢?总不能为了一粒米丢掉所有玉米.方案如下
要在网站中使用map api就要引用一个js文件,我们可以在这想办法,在script的属性中也有一个charset属性,添加它
<script ... charset="utf-8"></script>
下面是一些示例
用的map key为:t6new.cn的
默认示例(ie下会提示缺少对象)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAy_92lh6L5xhcKXiWFze7ahSeyyn5-963h60-vJRKrf4xaRdBuBTmF2UsZnFk8o95hGt2T99GRoVPiA"
type="text/javascript"></script>
<title>google map demo</title>
<script type="text/javascript">
//<![CDATA[
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.5429, 121.3776), 13);
geocoder = new GClientGeocoder();
}
}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
}
//]]>
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<input type="text" name="address" size="50" value="烟台市西盛街28号第一大道" onblur="showAddress(this.value);" />
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
</html>
meta示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAy_92lh6L5xhcKXiWFze7ahSeyyn5-963h60-vJRKrf4xaRdBuBTmF2UsZnFk8o95hGt2T99GRoVPiA"
type="text/javascript"></script>
<title>google map demo</title>
<script type="text/javascript">
//<![CDATA[
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.5429, 121.3776), 13);
geocoder = new GClientGeocoder();
}
}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
}
//]]>
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<input type="text" name="address" size="50" value="烟台市西盛街28号第一大道" onblur="showAddress(this.value);" />
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
</html>
script属性charset示例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAy_92lh6L5xhcKXiWFze7ahSeyyn5-963h60-vJRKrf4xaRdBuBTmF2UsZnFk8o95hGt2T99GRoVPiA"
type="text/javascript" charset="utf-8"></script>
<title>google map demo</title>
<script type="text/javascript">
//<![CDATA[
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.5429, 121.3776), 13);
geocoder = new GClientGeocoder();
}
}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
}
//]]>
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<input type="text" name="address" size="50" value="烟台市西盛街28号第一大道" onblur="showAddress(this.value);" />
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
</html>
在小站上的示例是基于script的charset属性: http://www.t6new.cn/feature/maptest.html
相关文章推荐
- Google Map API在IE6下出错的解决方法
- google map api key申请
- IE下jquery 访问 XML 数据时发生 parsererror, TypeError: 缺少对象 错误的解决方案
- GPS定位纬度,经度后,通过GOOGLE MAP API解析出地址
- 获得Google Map API Key(android map中使用)
- 转载--geolocation and get the address by Google Map api
- Google Map API和百度地图API用于地理编码
- Google Map API使用详解(九)——Google Map坐标系统总结(下)
- Google Map API使用详解(十九)——实现Google Map本地搜索框(上)
- GOOGLE发布针对as3的GOOGLE MAP API
- Google Map API
- GoogleMap api
- 研习了一下google map api
- 申请android google map API key
- Google Map API Generation
- 如何获取Google Map API Key
- iphone 开发 googleMap api
- iOS使用Google Map Api…
- Android Google Map实例 - MD5 、Google Map API Key获取(Android mapview)
- Google Map API