映射标记仅在清除浏览器缓存后加载

时间:2013-10-08 20:54:09

标签: javascript html internet-explorer google-maps google-maps-api-3

我的网站www.procomport.com仅适用于Google Chrome和Firefox。

每当我发布一个包含我所有代码的问题时,每个人都在大喊大叫说他们需要代码才能发布你还想要我的其他内容!? JS在Chrome和Firefox中完美运行,但没有别的。

的Javascript

var geocoder;
var map;
var lat1;
var lng1;
var lat2;
var lng2;
var range;
var htmlcard;
var initialLocation;
var measure;


function initialize() {



    var siberia = new google.maps.LatLng(34.0522, -118.2428);
    var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
    var browserSupportFlag = new Boolean();


    var address = document.getElementById("addressForm");
    //alert(address.value.trim().length);


    //alert(address.value.length);
    if (address.value.length <= 2) {
        if (navigator.geolocation) {
            browserSupportFlag = true;
            navigator.geolocation.getCurrentPosition(function (position) {
                initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

                //createMap2(initialLocation);

                load(initialLocation);

                lat1 = position.coords.latitude;
                lng1 = position.coords.longitude;

            }, function () {
                handleNoGeolocation(browserSupportFlag);
            });
        }
        // Browser doesn't support Geolocation
        else {
            browserSupportFlag = false;
            handleNoGeolocation(browserSupportFlag);
        }

        function handleNoGeolocation(errorFlag) {
            if (errorFlag == true) {
                //alert("Failed to find location.");
                //createMap(newyork);
                load(newyork);

            } else {
                //alert("Your browser doesn't support geolocation. We've placed you in Los Angeles.");
                //createMap(siberia);
                load(siberia);
            }
        }
    }
    else {
        geocoder = new google.maps.Geocoder();
        var address = document.getElementById("addressForm").value;

        geocoder.geocode({ 'address': address }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {

                load(results[0].geometry.location)

                lat1 = results[0].geometry.location.lat();
                lng1 = results[0].geometry.location.lng();

            }
        });

    }


}

function load(center) {

     range = document.getElementById("distance").value;

    if (range == "" || range == 0)
        {
            range = "200";
        }
    measure = document.getElementById("measure").value;

    if (measure !== "m") {
        measure == "km";
    }

    geocoder = new google.maps.Geocoder();
    var mapOptions1 = {
        zoom: 12,
        center: center,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions1);

    var marker = new google.maps.Marker({
        map: map,
        position: center
    });

    var professionFilter = document.getElementById("professionFilterValue").value;

    //alert(professionFilter);

    downloadUrl("xml.php?p=" + professionFilter, function (data) {

        var xml = data.responseXML; // xml file generated from xml.php

        var markers = xml.documentElement.getElementsByTagName("marker"); // parses XML and gets Markers From Data


        for (var i = 0; i < markers.length; i++) {


            // Sets infoWindow for specific marker 
            var infoWindow = new google.maps.InfoWindow({ maxwidth: 350 });

             google.maps.event.addListener(map, "click", function () { infoWindow.close(); });

            //========================================================================================= 
            // Sets Marker Attributes an Location

            lat2 = markers[i].getAttribute("lat");
            lng2 = markers[i].getAttribute("lng");

            var distance = getDistance(lat1, lng1, lat2, lng2)
            var display_name = markers[i].getAttribute('dname')

            var card = markers[i].getAttribute('card')
            var htmlCard = decodeURIComponent(card)

            if (getDistance(lat1, lng1, lat2, lng2) < range) {

                var point = new google.maps.LatLng(
                parseFloat(markers[i].getAttribute("lat")),
                parseFloat(markers[i].getAttribute("lng")));
                var html = htmlCard
                var icon = "https://www.procomport.com/site/www/images/computericon.png"
                var marker = new google.maps.Marker({
                    map: map,
                    position: point,
                    icon: "/site/www/images/computericon.png",
                    shadow: icon.shadow,
                    title: name
                });

                bindInfoWindow(marker, map, infoWindow, html);
            }
        }

        //=========================================================================================
    });
}
function bindInfoWindow(marker, map, infoWindow, html) {


    google.maps.event.addListener(marker, 'click', function () {
        setTimeout(function () { infoWindow.setContent(html); }, '1000');
        setTimeout(function () { infoWindow.open(map, marker); }, '1000');
        setTimeout(function () { infoWindow.close(); }, '5000');

    });

}
function downloadUrl(url, callback) {
    var request = window.ActiveXObject ?
    new ActiveXObject('Microsoft.XMLHTTP') :
    new XMLHttpRequest;

    request.onreadystatechange = function () {
        if (request.readyState == 4 && request.status == 200) {
            request.onreadystatechange = doNothing;
            callback(request, request.status);
        }
    };

    request.open('GET', url, true);
    request.send(null);
}
function doNothing() { }

function getDistance(lat11, lon11, lat22, lon22) {
    var R;

    if (measure == "km") {
        R = 6371;
    }
    else {
        R = 3959;
    }
    // km (change this constant to get miles)
    var dLat = (lat22 - lat11) * Math.PI / 180;
    var dLon = (lon22 - lon11) * Math.PI / 180;
    var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
    Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
    Math.sin(dLon / 2) * Math.sin(dLon / 2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    var d = R * c;
    if (d > 1) return Math.round(d);
    else if (d <= 1) return Math.round(d * 1000);

    return d;

}

就像我真的失去了我的想法我做错了什么我跑了W3验证器,因为我被告知并修复了很多错误(除了meta标签) Validator Results

准确诊断此问题需要哪些其他代码?

Internet Explorer控制台输出。

HTML1114: Codepage iso-8859-1 from (META tag) overrides conflicting codepage windows-1252 from (META tag) 
map.php
HTML1514: Extra "<body>" tag found. Only one "<body>" tag should exist per document. 
map.php, line 154 character 1
HTML1522: Invalid end tag: "</br>". Use "<br>" or "<br/>" instead. 
map.php, line 322 character 9
HTML1522: Invalid end tag: "</br>". Use "<br>" or "<br/>" instead. 
map.php, line 524 character 164
HTML1522: Invalid end tag: "</br>". Use "<br>" or "<br/>" instead. 
map.php, line 524 character 343
HTML1522: Invalid end tag: "</br>". Use "<br>" or "<br/>" instead. 
map.php, line 525 character 120
Invalid App Id: Must be a number or numeric string representing the application id. 

更新:

修复了所有IE错误 - 仍然没有标记

更新2:

每次清除浏览器缓存并重新加载页面时都取得了一些进展。

更新3:

地图甚至没有在Safari上加载

0 个答案:

没有答案