Google map API in IE6: Solution for lack of Objects

Source: Internet
Author: User
Anyone who has used the Google map API should notice that the JS script in the example is normal in FF, opera,... (non-IE6 browsers). An error will be reported in IE6:
Object missing
The Wrong row number generally points to the row created by the gmap2 object.

There are two solutions:
1. Specify charset = UTF-8 in Meta. For the reason, refer to Google.
2. What if charset in the application is not UTF-8? The solution is as follows:
To use the map API on a website, we need to reference a JS file. Here we can try to add a charset attribute in the script attribute.
<Script... charset = "UTF-8"> </SCRIPT>

Below are some examples
The map key used is

Default example (an object is missing in IE)

  1. <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  3. <Head>
  4. <Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
  5. <SCRIPT src = "http://maps.google.com/maps? File = API & V = 2 & Key = ABQIAAAAy_92lh6L5xhcKXiWFze7ahSeyyn5-963h60-vJRKrf4xaRdBuBTmF2UsZnFk8o95hGt2T99GRoVPiA"
  6. Type = "text/JavaScript"> </SCRIPT>
  7. <Title> Google map demo </title>
  8. <SCRIPT type = "text/JavaScript">
  9. // <! [CDATA [
  10. VaR map = NULL;
  11. VaR geocoder = NULL;
  12. Function initialize (){
  13. If (gbrowseriscompatible ()){
  14. Map = new gmap2 (document. getelementbyid ("map_canvas "));
  15. Map. setcenter (New glatlng (37.5429, 121.3776), 13 );
  16. Geocoder = new gclientgeocoder ();
  17. }
  18. }
  19. Function showaddress (Address ){
  20. If (geocoder ){
  21. Geocoder. getlatlng (
  22. Address,
  23. Function (point ){
  24. If (! Point ){
  25. Alert (address + "not found ");
  26. } Else {
  27. Map. setcenter (point, 13 );
  28. VaR marker = new gmarker (point );
  29. Map. addoverlay (Marker );
  30. Marker. openinfowindowhtml (Address );
  31. }
  32. }
  33. );
  34. }
  35. }
  36. //]>
  37. </SCRIPT>
  38. </Head>
  39. <Body onload = "initialize ()" onUnload = "gunload ()">
  40. <Input type = "text" name = "Address" size = "50" value = "No. 28 xisheng Street, Yantai City, 1st Avenue" onblur = "showaddress (this. Value);"/>
  41. <Div id = "map_canvas" style = "width: 500px; Height: 300px"> </div>
  42. </Body>
  43. </Html>

Meta example:

  1. <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  3. <Head>
  4. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
  5. <SCRIPT src = "http://maps.google.com/maps? File = API & V = 2 & Key = ABQIAAAAy_92lh6L5xhcKXiWFze7ahSeyyn5-963h60-vJRKrf4xaRdBuBTmF2UsZnFk8o95hGt2T99GRoVPiA"
  6. Type = "text/JavaScript"> </SCRIPT>
  7. <Title> Google map demo </title>
  8. <SCRIPT type = "text/JavaScript">
  9. // <! [CDATA [
  10. VaR map = NULL;
  11. VaR geocoder = NULL;
  12. Function initialize (){
  13. If (gbrowseriscompatible ()){
  14. Map = new gmap2 (document. getelementbyid ("map_canvas "));
  15. Map. setcenter (New glatlng (37.5429, 121.3776), 13 );
  16. Geocoder = new gclientgeocoder ();
  17. }
  18. }
  19. Function showaddress (Address ){
  20. If (geocoder ){
  21. Geocoder. getlatlng (
  22. Address,
  23. Function (point ){
  24. If (! Point ){
  25. Alert (address + "not found ");
  26. } Else {
  27. Map. setcenter (point, 13 );
  28. VaR marker = new gmarker (point );
  29. Map. addoverlay (Marker );
  30. Marker. openinfowindowhtml (Address );
  31. }
  32. }
  33. );
  34. }
  35. }
  36. //]>
  37. </SCRIPT>
  38. </Head>
  39. <Body onload = "initialize ()" onUnload = "gunload ()">
  40. <Input type = "text" name = "Address" size = "50" value = "No. 28 xisheng Street, Yantai City, 1st Avenue" onblur = "showaddress (this. Value);"/>
  41. <Div id = "map_canvas" style = "width: 500px; Height: 300px"> </div>
  42. </Body>
  43. </Html>

Script Attribute charset example

  1. <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  3. <Head>
  4. <Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
  5. <SCRIPT src = "http://maps.google.com/maps? File = API & V = 2 & Key = ABQIAAAAy_92lh6L5xhcKXiWFze7ahSeyyn5-963h60-vJRKrf4xaRdBuBTmF2UsZnFk8o95hGt2T99GRoVPiA"
  6. Type = "text/JavaScript" charset = "UTF-8"> </SCRIPT>
  7. <Title> Google map demo </title>
  8. <SCRIPT type = "text/JavaScript">
  9. // <! [CDATA [
  10. VaR map = NULL;
  11. VaR geocoder = NULL;
  12. Function initialize (){
  13. If (gbrowseriscompatible ()){
  14. Map = new gmap2 (document. getelementbyid ("map_canvas "));
  15. Map. setcenter (New glatlng (37.5429, 121.3776), 13 );
  16. Geocoder = new gclientgeocoder ();
  17. }
  18. }
  19. Function showaddress (Address ){
  20. If (geocoder ){
  21. Geocoder. getlatlng (
  22. Address,
  23. Function (point ){
  24. If (! Point ){
  25. Alert (address + "not found ");
  26. } Else {
  27. Map. setcenter (point, 13 );
  28. VaR marker = new gmarker (point );
  29. Map. addoverlay (Marker );
  30. Marker. openinfowindowhtml (Address );
  31. }
  32. }
  33. );
  34. }
  35. }
  36. //]>
  37. </SCRIPT>
  38. </Head>
  39. <Body onload = "initialize ()" onUnload = "gunload ()">
  40. <Input type = "text" name = "Address" size = "50" value = "No. 28 xisheng Street, Yantai City, 1st Avenue" onblur = "showaddress (this. Value);"/>
  41. <Div id = "map_canvas" style = "width: 500px; Height: 300px"> </div>
  42. </Body>
  43. </Html>

The example on the small site is based on the charset attribute of the script:
Http://www.t6new.cn/feature/maptest.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.