2012-03-21 8 views
-1

私は現在の場所から最も近い10のマーカーを見つける必要があるプロジェクトをやっています。AndroidのGoogleマップで。 これらのものを表示するAPIまたは組み込みの関数/クラスはありますか? 私はAndroidのGoogleマップについてほとんど知識がありません。最寄りのGoogleマーカーを検索するには?

私はPlzは私を助けてPlzを

...私のリストビューのグーグルマップとその緯度長いタイトルの10の最も近い著しい場所を見つける必要があります。!

+0

これは[最も近いマーカーを見つける](http://stackoverflow.com/questions/4057665/google-maps-api-v3-find-nearest-markers)助けてもらえます –

答えて

4

2つのジオポイント間の距離を見つけるには、次の方法を使用する必要があります。

/** 
* 
* @param lat1 Latitude of the First Location 
* @param lng1 Logitude of the First Location 
* @param lat2 Latitude of the Second Location 
* @param lng2 Longitude of the Second Location 
* @return distance between two lat-lon in float format 
*/ 

public static float distFrom (float lat1, float lng1, float lat2, float lng2) 
{ 
    double earthRadius = 3958.75; 
    double dLat = Math.toRadians(lat2-lat1); 
    double dLng = Math.toRadians(lng2-lng1); 
    double a = Math.sin(dLat/2) * Math.sin(dLat/2) + 
    Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * 
    Math.sin(dLng/2) * Math.sin(dLng/2); 
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
    double dist = earthRadius * c; 

    int meterConversion = 1609; 

    return new Float(dist * meterConversion).floatValue(); 
} 

ここにあなたの最初の地域コードは、あなたの現在の位置の地域コード及び他の地理のポイントになりますが、あなたと比較したい地理ポイントである、あなたはそれのためにループを実行する必要があります。

+0

@ Android。私の質問が見えますか? https://stackoverflow.com/questions/48563909/illegalstateexception-fragment-already-added-android?noredirect=1#comment84192332_48563909 –

1

あなたの描いた方法で近くのマーカーを取得する機能はないとは思いますが、各マーカーまでの距離を計算して結果を並べ替えることで独自のマーカーを作成することができます。

関連する問題