我的谷歌地图距离查找器不能正常工作与SSL

My Google Maps Distance Finder Isnt Working Correctly With SSL

本文关键字:工作 SSL 常工作 距离 谷歌地图 查找 不能 我的      更新时间:2023-09-26

如果没有在IE中抛出关于SSL安全的错误,我似乎无法在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,但我不知道如何改变这个

<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>

API的版本2只能由高级会员通过SSL访问。

版本3可以。

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