2011-07-27 3 views
1

私はSSLで正しく動作するようには思えません。私がJavascriptでそれほど偉大ではないので、助けてください。私のGoogleマップ距離ファインダーが正しくSSLで動作していません

<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を使用していることですが、私はこれを変更する方法は考えています。

答えて

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>に変更してください。

0

APIのバージョン2は、プレミアメンバーによるSSL経由でのみアクセスできます。

バージョン3は問題ありません。

出典:http://code.google.com/apis/maps/faq.html#ssl(SSLセクションの最後のセクションでは、正確なエラーを持っている)

関連する問題