Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

javascript - Google Maps API GeoJSON not working with IE 11, but works in Chrome

I have a google map that loads markers from a GeoJSON file that runs on localhost in Visual Studio 2013. It also runs in chrome (from an IIS server) but will not run in IE version 11. The map shows up, but the markers from the JSON file do not. Why would this work in Chrome on IIS 8, and IE 11 through VS, but not IE 11 on IIS 8?

    var map;
    var infowindow = new google.maps.InfoWindow({ });

    function initialize() {

            map = new google.maps.Map(document.getElementById('googleMap'), {
            center: new google.maps.LatLng(15.508742, -0.120850),
            zoom: 2,
            mapTypeId: google.maps.MapTypeId.HYBRID,
            scrollwheel: false 
        });

        google.maps.event.addListener(map, 'click', function() {
            infowindow.close();
        });

        // Load a GeoJSON from the same server as our demo.
        map.data.loadGeoJson('locations.json');

        // Set event listener for each feature.
        map.data.addListener('click', function (event) {
            infowindow.setContent("<div> " + event.feature.getProperty('city') + " " + event.feature.getProperty('date') + "<br>" + event.feature.getProperty('course') + "<br>Sponsored by: " + event.feature.getProperty('sponsor') + "<br>" + "<a href=" + "/Training.aspx" + ">Click here to Register</a>" + "</div>");
            infowindow.setPosition(event.latLng);
            infowindow.setOptions({ pixelOffset: new google.maps.Size(0, -34) });
            infowindow.open(map);

        });

        map.data.addListener('mouseover', function (event) {
            //infowindow.setContent("<div class="map_info_box" > " + event.feature.getProperty('city') + " " + event.feature.getProperty('date') + "<br>" + event.feature.getProperty('course') + "<br>Sponsored by: " + event.feature.getProperty('sponsor') + "<br>" + "<a href=" + "/Training.aspx" + ">Click here to Register</a>" + "</div>");
            infowindow.setContent("<div> " + event.feature.getProperty('city') + " " + event.feature.getProperty('date') + "<br>" + event.feature.getProperty('course') + "<br>Sponsored by: " + event.feature.getProperty('sponsor') + "<br>" + "<a href=" + "/Training.aspx" + ">Click here to Register</a>" + "</div>");
            infowindow.setPosition(event.latLng);
            infowindow.setOptions({ pixelOffset: new google.maps.Size(0, -34) });
            infowindow.open(map);
        });

    }

    google.maps.event.addDomListener(window, 'load', initialize);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Compatibility view in IE prevented the loading of the geoJSON file. I put

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

at the top of the page and it solved the issue.

Many thanks to geocodezip who pointed me in the right direction in the comments above.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...