1

我正在用 javascript 编写一些代码,我需要它在大多数浏览器上工作,但它只适用于 googleChrome、IE 和 FF 不要调用此函数:

<script type="text/javascript">
  showLocation(<?php print "\"$citta2\""?>,<?php print "\"$row[nome] $row[cognome]\""?>,<?php print "\"$row[id]\""?>); return false;
  </script>

(我知道它不会调用它,因为它应该做的第一件事是发出警报)你知道为什么它只能在 chrome 中工作吗?如果您需要所有文件,我可以将其发布在下面,但它有点长,我也很肯定问题出在那个电话上。

编辑1:这里是显示位置代码:

function showLocation(address2,nomi0,id0) {
            alert("1");
    var nomi1 = nomi0;
    var id1 = id0;
    geocoder.getLocations(address1, function (response) {

        if (!response || response.Status.code != 200)
        {
            alert("Errore con il primo indirizzo");
        }
        else
        {
            location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
            geocoder.getLocations(address2, function (response) 
            {
                if (!response || response.Status.code != 200)
                {
                    alert("Errore con il secondo indirizzo");
                }
                else
                {
                    location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                    calculateDistance(nomi1,id1);
                }
            });
        }
    });
}

(它使用google maps api来获取城市的纬度和经度)

4

1 回答 1

-1

没有答案(到目前为止)只需要超过评论中允许的 600 个字符。

首先,让您的脚本标签更易于阅读,并添加一些调试:

<script type="text/javascript">
    try {
        if (window.showLocation)
        {
            showLocation(<?php print "'{$citta2}','{$row[nome]} {$row[cognome]}','{$row[id]}'"; ?>);
        }
        else
        {
            // if you see this message:
            // then you have a syntax error before or within the creation of showLocation
            alert("showLocation has not been created!");
        }
    }
    catch (e) {
        alert("Error from caller: " + e);
    }
</script>



现在在您的其他代码中,添加一些调试:

function showLocation(address2,nomi0,id0) {
    try {
        alert("1");
        var nomi1 = nomi0;
        var id1 = id0;
        geocoder.getLocations(address1, function (response)
        {
            try
            {
                if (!response || response.Status.code != 200)
                {
                    alert("Errore con il primo indirizzo");
                }
                else
                {
                    location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                    geocoder.getLocations(address2, function (response) 
                    {
                        try
                        {
                            if (!response || response.Status.code != 200)
                            {
                                alert("Errore con il secondo indirizzo");
                            }
                            else
                            {
                                location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                                calculateDistance(nomi1,id1);
                            }
                        }
                        catch (e)
                        {
                            alert("Error in callback#2: "+ e);
                        }
                    });
                }
            }
            catch (e)
            {
                alert("Error in callback#1: " + e);
            }
        });
    }
    catch (e)
    {
        alert("Error in functon: " + e);
    }
}




_添加了更多调试警报_

于 2012-11-14T10:26:41.963 回答