0

Googleマップを使用している最寄りのショップを表示している会社のアプリを作成しようとしています。私は、これは私のJavaクラスのコードで何をすべきかAPIと分からない:Googleマップで最寄りのマーカーを取得する方法

private GoogleMap mMap; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_contact_page); 
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 
} 

@Override 
public void onMapReady(GoogleMap googleMap) { 
    mMap = googleMap; 
    LatLng Alexandra = new LatLng(-45.249167, 169.379722); 
    mMap.addMarker(new MarkerOptions().position(Alexandra).title("Bin Inn Alexandra")); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(Alexandra)); 
}} 

と、これは私のXMLコードでは、IMは、お店の情報を入れるために起こっているボタンを無視:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:gravity="center"> 

<fragment 
    android:id="@+id/map" 
    android:name="com.google.android.gms.maps.SupportMapFragment" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    tools:context=".MapsActivity" /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 

+0

がここhttps://stackoverflow.com/questions/見てみましょうボタンのonclickこの機能を使用中nearby places map api 32284708/how-to-always-detect-nearby-marker-locations-go-in-google-in-google – Chei

答えて

0

ユーザーエクスペリエンスの観点からこれを行う方法はいくつかあります。近くのユーザーが利用できる駐車場を表示するアプリがあります。市内に100の駐車場が広がっているとしましょう。現在の位置から500m以内にある駐車場のみを表示する初期マップズームを決定します。ユーザーがズームアウトすると、より多くのスポットが表示されます。駐車場はすべて表示されています。

今、私はあなたの問題の声明から、地図上で最も近い店だけを表示したいのか、何を表示するのかは明らかではありません。そのような場合は、Google Distance Matrix APIのようなものを使用する必要があります。起源と目的地latとlongをとり、距離と所要時間を示します。しかし、それがあなたにとって過剰な場合は、マップ上の2点間の距離を計算し、現在の位置からの距離が最も小さい点のマーカーを表示する方がずっと簡単です。リファレンスとしてこれを使用する - コードを理解することがCalculate distance between two points in google maps V3

+0

私がしようとしているのは、アプリがそれにズームした最寄りの店を見つけて、インフォメーション:電話番号、住所、Eメールアドレスなどのマーカーポップアップに関する情報が表示されますが、他のすべてのマーカーは、顧客アプリを使用してニュージーランドの別の都市を訪問したいとそこにビンインがあるかどうかを見たいと思っています。 –

+0

ああ、私はJavaScriptを使用していません(あなたのリンクではJavaScriptを使用しています) –

0

使用このURLを

そして

private String getUrl(double latitude, double longitude) { 
    StringBuilder googlePlacesUrl = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?"); 
    googlePlacesUrl.append("location=" + latitude + "," + longitude); 
    googlePlacesUrl.append("&radius=" + PROXIMITY_RADIUS); 
    googlePlacesUrl.append("&keyword=**companyname**"); 
    googlePlacesUrl.append("&sensor=true"); 
    googlePlacesUrl.append("&key=" + "API KEY"); 
    Log.d("getUrl", googlePlacesUrl.toString()); 
    return (googlePlacesUrl.toString()); 
} 
関連する問題