2012-01-24 15 views
0

住所から経度と緯度を取得するために、これまで働いていた秘密のスクリプトがあります。 問題は提出できません。提出ボタンは経度と緯度を取得するために使用されます。Googleマップapi v2住所問題の経度と緯度

私は次のようにしたいと考えています: アドレスは隠しフィールドに配置されます。 (私のCMS、ExpressionEngineによって埋められています) ページ上に経緯度を入力し、緯度を2つの入力フィールド に集めてsubmitを押して完了します。

これを行うには、これまでのところ次のコードを使用します。 助けてください。

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
     <head> 
     <title>Longitude and Latitude from address</title> 

     <script src="http://maps.google.com/maps?file=api&v=2&key=YOUR KEY" type="text/javascript" charset="utf-8"> 

     </script> 
      <script type="text/javascript"> 
     //<![CDATA[ 

     function load() { 
      if (GBrowserIsCompatible()) { 
      geocoder = new GClientGeocoder(); 
      } 
     } 

     function showAddress(geolocation) { 
      if (geocoder) { 
      geocoder.getLatLng(
       geolocation, 
       function(point) { 
       if (!point) { 
        alert(geolocation + " not found"); 
       } else { 
        document.geoform.longitude.value = point.x; 
        document.geoform.latitude.value = point.y; 
       } 
       } 
      ); 
      } 
     } 

     //]]> 
     </script> 
     </head> 
     <body onload="load()"> 

    <form action="#" name="geoform" id="geoform" onsubmit="showAddress(this.geolocation.value); return false"> 
    <input type="hidden" name="geolocation" value="Address goes here, populated by cms" size="50" /> 

    Decimal Longitude: 
    <input name="longitude" type="text" id="longitude" value="" /> 

    Decimal Latitude: 
    <input name="latitude" type="text" id="latitude" value="" /> 

    <input type="submit" value="Longitude/latitude codes" /> 
    </form> 
    </body> 
    </html> 
+0

どのようなエラーが表示されていますか? – Unknown

+0

Hello Matrix、私はエラーを取得していません。もし私が上記のスクリプトを使用すると、私はlongとlatを得るでしょう。フォームから「返品偽」を取り除くと、それは提出しているものの、長くて奇妙なものは得られません。だから、私はページの読み込みに使用したいです。 (私は試してみたが、運がない) –

答えて

1

フォームを送信する頃に、住所をジオコードするリクエストを送信するのが遅すぎます。 ページの読み込み時にアドレスをジオコーディングしてから、フォームを送信する方がよいでしょう。ところで

function load() { 
     if (GBrowserIsCompatible()) { 
     geocoder = new GClientGeocoder(); 
     geocoder.getLatLng(
      document.geoform.geolocation.value, 
      function(point) { 
      if (!point) { 
       alert(geolocation + " not found"); 
      } else { 
       document.geoform.longitude.value = point.x; 
       document.geoform.latitude.value = point.y; 
      } 
      } 
     ); 
     } 
    } 

、三つの重要なポイント:

  1. それは、Googleマップ上で結果を表示せずにジオコードするGoogleのTerms of Service反対です。 10.1.1(g)を参照してください
  2. もうv2で開発するべきではありません。それは廃止され、間もなく廃止される予定です。 Use v3 instead
  3. web service geocoding APIがあります。これをサーバーですべて実行すると、この複雑さを避けることができます。
関連する問題