我的Google Maps Distance Finder无法正常使用SSL

时间:2011-07-27 17:38:45

标签: javascript google-maps

我似乎无法让它在SSL中正常工作而不会在IE中引发有关SSL安全性的错误。请帮忙,因为我对Javascript不是那么好。

<script src="//maps.google.com/maps?file=api&v=2&key=MY_API" type="text/javascript"></script>

    <script type="text/javascript">

    var geocoder, location1, location2, gDir;

    function initialize() {
            geocoder = new GClientGeocoder();
            gDir = new GDirections();
            GEvent.addListener(gDir, "load", function() {
                    var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
                    var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
                    var shippingPrice = drivingDistanceMiles * 1.50;
                    document.getElementById('results').innerHTML = '<p><strong style="color:red;">Factory Address: </strong>' + location1.address + ' </p><p><strong  style="color:red;">Your Address: </strong>' + location2.address + '</p><p><strong  style="color:red;">Driving Distance: </strong>' + drivingDistanceMiles.toFixed(1) + ' miles </p><p><strong  style="color:red;">Estimated Shipping Cost:</strong> $' + shippingPrice.toFixed(2) + ' USD';
            });
    }

    function showLocation() {
            geocoder.getLocations(document.forms[0].address1.value, function (response) {
                    if (!response || response.Status.code != 200)
                    {
                            alert("Sorry, we were unable to geocode the first address");
                    }
                    else
                    {
                            location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                            geocoder.getLocations(document.forms[0].address2.value, function (response) {
                                    if (!response || response.Status.code != 200)
                                    {
                                            alert("Sorry, we were unable to geocode the second address");
                                    }
                                    else
                                    {
                                            location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                                            gDir.load('from: ' + location1.address + ' to: ' + location2.address);
                                    }
                            });
                    }
            });
    }

    </script>

<body onload="initialize()">
<h3 style="color:red;">Estimate Your Shipping Cost</h3>

    <form action="#" onsubmit="showLocation(); return false;">
            <p style="color:white;">
                    <input type="text" name="address1" value="Douglas, GA" style="display:none" />
                    Enter Your Address:<br/>
                    <input type="text" name="address2" placeHolder="Your Address" />
                    <input type="submit" value="Search" />
            </p>
    </form>

    <p id="results"  style="color:white;"></p>

我的猜测是,它使用的是api的第2版,但我不知道如何更改它。

2 个答案:

答案 0 :(得分:0)

<script src="//maps.google.com/maps?file=api&v=2&key=MY_API" type="text/javascript"></script>更改为<script src="https//maps.google.com/maps?file=api&v=2&key=MY_API" type="text/javascript"></script>

答案 1 :(得分:0)

API的第2版只能由Premier会员通过SSL访问。

版本3没问题。

来源:http://code.google.com/apis/maps/faq.html#ssl(SSL部分的最后一部分有您的确切错误)