2016-12-05 5 views
0

마커에서 BottomSheet의 NestedScrollView까지 세부 정보 (데이터)를 가져 오는 문제가 있습니다. 마커를 클릭하면 NestedScrollView가 맨 아래에서 위로 스크롤하여 해당 데이터를 표시합니다. 데이터를 얻기 위해 json을 사용하고 있습니다. Google Map에서 마커를 클릭하면 마커에서 BottomSheet로 데이터를 가져 오는 방법

내 소스 코드 :

public class SeekingMapActivity extends AppCompatActivity implements 
    GoogleApiClient.OnConnectionFailedListener, 
    GoogleApiClient.ConnectionCallbacks, 
    View.OnClickListener { 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_seeking_main); 

    ... 

    ArrayList<HashMap<String, String>> location = null; 
    String url = "myURL"; 
    try { 
     JSONArray data = new JSONArray(getHttpGet(url)); 
     location = new ArrayList<HashMap<String, String>>(); 
     HashMap<String, String> map; 

     for (int i = 0; i < data.length(); i++) { 
      JSONObject c = data.getJSONObject(i); 

      map = new HashMap<String, String>(); 
      map.put("title", c.getString("title")); 
      map.put("avatar", c.getString("avatar")); 
      map.put("lat", c.getString("lat")); 
      map.put("mapLong", c.getString("mapLong")); 
      map.put("address", c.getString("address")); 
      location.add(map); 
     } 

    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 

    // googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 

    IconGenerator tc = new IconGenerator(this); 
    String price = "1200K"; 
    Bitmap bmp = tc.makeIcon(price); // pass the text you want. 

    lat = Double.parseDouble(location.get(0).get("lat").toString()); 
    mapLong = Double.parseDouble(location.get(0).get("mapLong").toString()); 

    LatLng coordinate = new LatLng(lat, mapLong); 
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 
    googleMap.getUiSettings().setMapToolbarEnabled(false); 
    googleMap.getUiSettings().setRotateGesturesEnabled(true);  // Enable RotateGestures 
    googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(coordinate, 15)); 

    for (int i = 0; i < location.size(); i++) { 

     lat = Double.parseDouble(location.get(i).get("lat").toString()); 
     mapLong = Double.parseDouble(location.get(i).get("mapLong").toString()); 

     String title = location.get(i).get("title").toString(); 
     String avatar = location.get(i).get("avatar".toString()); 
     String address = location.get(i).get("address").toString(); 

     MarkerOptions marker = new MarkerOptions().position(new LatLng(lat, mapLong)) 
       .title(title) 
       .snippet(address) 
       .icon(BitmapDescriptorFactory.fromBitmap(bmp)); // .anchor(0.5f, 0.6f) 
     googleMap.addMarker(marker); 

     googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() 
     { 
      @Override 
      public boolean onMarkerClick(Marker arg0) { 
       if(isClick==false) 
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); 
       else 
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); 

       isClick=!isClick; 
       // Toast.makeText(SeekingMapActivity.this, arg0.getTitle(), Toast.LENGTH_SHORT).show();// display toast 
       return true; 
      } 
     }); 
    } 
} 
... 

} BottomSheet의

레이아웃 :

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/bottom_sheet" 
    android:layout_width="match_parent" 
    android:layout_height="270dp" 
    android:clipToPadding="true" 
    android:background="@color/white" 
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior" 
    > <!--   android:background="@android:color/background_holo_light" --> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 
     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/mercedes"/> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="1,200,000" 
      android:textSize="20dp" 
      android:textStyle="bold"/> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 
       <TextView 
        android:id="@+id/textView1b" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Số cửa: 4 cửa" 
        android:textSize="14dp"/> 
       <!-- android:textAppearance="?android:attr/textAppearanceMedium" --> 
       <TextView 
        android:id="@+id/textView1c" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Số ghế: 4 chỗ" 
        android:textSize="14dp"/> 
       </LinearLayout> 

     <TextView 
      android:id="@+id/textView1d" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Địa chỉ: Quân Cầu giấy, Hà Nội" 
      android:textSize="14dp" /> 

     <TextView 
      android:id="@+id/textView1e" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="KIỂM TRA TÌNH TRẠNG XE" 
      android:textStyle="bold" 
      android:textColor="@color/greenColor"/> 

    </LinearLayout> 
</android.support.v4.widget.NestedScrollView> 

나는 예

NestedScrollView

에 업체에서 데이터를 얻을하는 방법을 모른다 :

When click: Marker A, data of marker A will display on NestedScrollView 
      Marker B, data of marker B will display on NestedScrollView 

자세한 내용이 필요하면 더 게시하게됩니다.

답변

1

1 -

3 모델 유형의 ArrayList를 만들기 - -

이 ... 제목, 아바타, 주소 등처럼 속성을 가진 모델 클래스를 만듭니다 당신의 ArrayList에 모든 데이터를 추가

4 - 이제 마커의 onMarkerClick 방법에서, 루프 반복하고 아래처럼 ArrayList의 제목/고유 ID의 위치와 그 마커의 제목이나 고유 ID를 비교 :

googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { 
      @Override 
      public boolean onMarkerClick(Marker marker) { 
       for (int i = 0; i < arrayList.size(); i++) { 
        if (marker.getTitle().equals(finalMSearchResultModel.getRecords().get(i).getHotelName())) { 
        // YOUR ACTION GOES HERE 
        } 
       } 
       return false; 
      } 
     }); 
+0

수 당신은 그 솔루션을 더 자세히 설명해 주시겠습니까? 나중에 마커 및 다른 순간을 어떻게 선언합니까? – Morozov

+0

@ 모로 조프 : 요점을 모르겠다. 요점을 자세히 설명해 주시겠습니까? – Bhavnik