使用COM打开从V2转换为V3

时间:2014-01-08 12:43:05

标签: internet-explorer google-maps-api-3 com

我一直在以一种略微不寻常的方式使用V2 maps API,因为我使用IE作为COM对象并使用Document对象的Write方法将JS和HTML代码放入COM浏览器对象

我必须使用这里的技巧来动态加载JS http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml

我已将下面的V3代码粘贴到无法正常工作的地方。我不是JS专家所以我确定它有一些问题

任何指针都会被暗示

也许它的loadjavascriptcss技巧正在停止工作,但我有几个没有成功

由于

        <!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&amp;callback=map_callback&amp;sensor=false&amp;key=AIzaSyCtZmbJtVVerKBh4L-iZCuDhG9OWIRs7x4&amp;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> 

0 个答案:

没有答案