2013-05-03 2 views
0

마커를 많이 만들었습니다. 마커의 각 정보 창이 필요합니다. 고유 한 정보 창이 필요합니다. 그러나 정보 창이 xml로 작성되었지만 작동하지 않습니다. 따라서 하나의 이미지가 나타날 때마다 myMap.setInfoWindowAdapter 토스트에 구글 맵스의 다른 마커에 대해 서로 다른 정보를 추가하는 방법 안드로이드에 대한 API v2

// Setting a custom info window adapter for the google map 
myMap.setInfoWindowAdapter(new InfoWindowAdapter() { 

    // Use default InfoWindow frame 

    public View getInfoWindow(Marker arg0) { 
     return null; 
    } 

    // Defines the contents of the InfoWindow 

    public View getInfoContents(Marker marker) { 

     // Getting view from the layout file info_window_layout 
     View v = getLayoutInflater().inflate(
       R.layout.info_window_layout, null); 

     // Getting the position from the marker 
     LatLng latLng = marker.getPosition(); 
     Double latitude=latLng.latitude; 
     Double langitude=latLng.longitude; 

     String lat = String.format("%.6f", latitude); 
     String lng = String.format("%.6f", langitude); 

     Toast.makeText(getApplicationContext(), lat+"----"+lng,Toast.LENGTH_SHORT).show(); 
     // Getting reference to the TextView to set longitude 
    TextView tvLng = (TextView) v.findViewById(R.id.tv1); 
    ImageView icon = (ImageView) v.findViewById(R.id.icons); 

    if(lat.equals("73.057130") && lng.equals("33.721140")) 
    { 
     icon.setImageResource(R.drawable.hbl_icon); 

    } 
    else 
    { 

     icon.setImageResource(R.drawable.alflah_icon); 
    } 
     // Returning the view containing InfoWindow contents 
     return v; 

    } 

}); 

은 같은 위도을 보여주고 있지만 정보 창은 조건 항상 다른 condition.everything의 이미지를 보여주는 잘 작동하는 경우에 이미지를 표시되지 표시되지만 이미지가 제대로 표시되지 친절하게 도와주세요. 내 XML은 다음과 같습니다

여기
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/icons" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" /> 

    <TextView 
     android:id="@+id/tv1" 
     android:text="Get Directions" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" /> 

</LinearLayout> 
+0

@ m_kiani - 긴 코드를 게시하지 마십시오 ... 요구 사항에 맞는 코드를 게시해야합니다 ... 편집하여 불필요한 코드를 제거하십시오. 최선을 다해 도와 드리겠습니다. – TheFlash

+0

@Pratik 나는 그것을 편집했다. 제발 도움이 .. –

+0

@ m_kiani - 당신은 올바른 논리를 구현했다고 생각합니다 .. 위도와 로그 위치에 따르면 .. 당신은 아이콘을 설정하고 있습니다. 그래서 작동하지 않습니까? – TheFlash

답변

0
for(int i = 0 ; i < arraylist.size();i++){ 
     addMarker(mapview,arraylistLat.get(i),arraylistLong.get(i),title.get(i),arraysnippet.get(i),imageid[i]); 
    } 

private void addMarker(GoogleMap map, double lat, double lon, 
      String string, String string2,int imgid) { 
     map.addMarker(new MarkerOptions().position(new LatLng(lat, lon)) 
       .title(string).snippet(string2).icon(BitmapDescriptorFactory.fromResource(imgid)); 
    } 

imgid는 드로어 블 리소스의 ID입니다.

1

this bug으로 인해 Marker을 식별하는 데 LatLng을 사용하면 안됩니다.

대신 제목/스 니펫을 사용하고 해당 값에 ifs를 사용하거나 모든 마커를 Map<Marker, YourModel> 개 갖고 아이콘 리소스 ID를 해당 모델에 보관할 수 있습니다.

Marker.setData(Object)Object Marker.getData()과 같은 기능을 추가하고 아이콘 리소스 ID가 마커에 가까운 모델로 유지하는 Android Maps Extensions을 사용할 수 있습니다.