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>

(最初に行うべきことはアラートを作成することであるため、それを呼び出さないことは知っています)それがクロムでのみ機能する理由を知っていますか?すべてのファイルが必要な場合は、以下に投稿できますが、少し長いです。問題はその呼び出しにあると確信しています。

edit1: ここに showLocation コードがあります:

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 に答える