2012-03-28 16 views
0

入力ボックスに住所や郵便番号を追加して、別の入力ボックスにgoogle latituteとlongituteを表示できるスクリプトをどこからでも探しています。 Googleマップ緯度/経度検索スクリプト

私はこのウェブサイトは、このないことが判明:

http://www.doogal.co.uk/LatLong.php

しかし、私はちょうどあなたが検索、緯度と経度の部品を持っている部分を探して、そのあまり必要ありません。

誰でもこれを行うための情報やURL、スクリプトを提供できますか?

私が知っているのは、アドレスマップです....私はちょうど緯度と経度に住所が必要です。

+0

Google TOSによると、Googleマップでジオコーディングを使用する必要があります。それ以外の場合は許可されません。 –

答えて

1

Google Maps APIを使用する場合は、住所をジオコードするのは非常に簡単です。 addressは、ユーザーが住所を入力するテキストフィールドです。 latlngは、出力されたlat/longを保持するテキストフィールドです。

$('#searchButton').click(function() { 
    var geocoder = new google.maps.Geocoder(); 
    geocoder.geocode({'address': $('#address').val() }, function(data, status) { 
    if (status == google.maps.GeocoderStatus.OK) { 
     $('#latlng').val(data[0].geometry.location.lat+", "+data[0].geometry.location.lng); 
    else { 
     alert("Geocode was not successful for the following reason: " + status); 
    } 
    }); 
    return false; 
}); 

あなたはAPIキーを取得し、Google Geocoding APIを実装する必要がhttps://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple

1

彼らはthat page上で使用しているコードは次のとおりです。

function Geocode() 
      { 
       $("#locations").html(""); 
       $("#error").html(""); 
       // geocode with google.maps.Geocoder 
       var localSearch = new google.maps.Geocoder(); 
       var postcode = $("#postcode").val(); 
       localSearch.geocode({ 'address': postcode }, 
        function(results, status) { 
         if (results.length == 1) { 
          var result = results[0]; 
          var location = result.geometry.location; 
          GotoLocation(location); 
         } 
         else if (results.length > 1) { 
          $("#error").html("Multiple addresses found"); 
          // build a list of possible addresses 
          var html = ""; 
          for (var i=0; i<results.length; i++) { 
           html += '<a href="javascript:GotoLocation(new google.maps.LatLng(' + 
            results[i].geometry.location.lat() + ', ' + results[i].geometry.location.lng() + '))">' + 
            results[i].formatted_address + "</a><br/>"; 
          } 
          $("#locations").html(html); 
         } 
         else { 
          $("#error").html("Address not found"); 
         } 
        }); 
      } 

#postcodeを使用すると、そのサイト側のアドレスを入力する場所であり、forループ内results[i].geometry.location.lat() + ', ' + results[i].geometry.location.lng()は、あなたの緯度/長いだろう...

0

を参照してください。

また、geocoder.usも無料のソリューションを提供します。

関連する問題