2011-12-28 16 views
7

私はGoogleマップで作業しています。郵便番号の中心付近で5マイルの半径内を検索できるようにする必要があります緯度/経度のマイルへの変換を把握することです。緯度/経度から1マイルへの変換

+0

これは実際にプログラミングの質問ではなく、単一の変換はありません。 –

+0

[Googleのジオメトリライブラリ](http://code.google.com/apis/maps/documentation/javascript/geometry.html#Distance)で距離を計算できます。 –

答えて

3

Googleはあなたの友人です。 「緯度経度から数マイルへの変換」の最初の数回の結果でこれを見つけました。http://www.movable-type.co.uk/scripts/latlong.html

JavaScriptコードもいくつかあります。ちょうどメモ、それはKMの結果を与えるが、それは簡単にマイルに変換することができます。

7

Google's Geometry libraryを使用した基本的な考え方です。

ジオメトリライブラリを追加することを忘れないでください。 Googleマップライブラリとは別のものです。

<script type="text/javascript" 
    src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false"> 
</script> 

使用例:

//the distance function defaults to km. 
    //to use miles add the radius of the earth in miles as the 3rd param. 
    //earths radius in miles == 3956.6 
    var distance = 
     google.maps.geometry.spherical.computeDistanceBetween(
      /* from LatLng */, 
      /* to LatLng */, 
      /* radius of the earth */ 
    ); 

    if (distance <= 5) { //less or equal to five miles 
     var marker = new google.maps.Marker({ 
      map: map, 
      position: //LatLng 
     });    
    } 

私は例のアクションでこののfiddleを持っています。

関連する問題