2013-05-03 4 views
26

Android 용 Google MAP API V2가 통합되어 있습니다. 내 마커의 Onclick에서 사용자 정의 정보 창을 갖고 싶습니다. 그것까지는 괜찮습니다. 나는 그것을 통합했다.Android Google지도 API V2 : 마커의 오른쪽에 맞춤 정보 창 열기

내가 원하는 것 : 마커의 오른쪽 대신 마커의 오른쪽에 내 사용자 정의 정보 윈도우를 표시하고 싶습니다.

public class MainActivity extends FragmentActivity { 

    private MainMapFragement mapFragment; 
    private HashMap<Marker, EventInfo> eventMarkerMap; 


    Marker ThirdMarker; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     mapFragment = new MainMapFragement(); 
     // FragmentTransaction ft = getFragmentManager().beginTransaction(); 
     FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); 
     ft.add(R.id.map, mapFragment); 
     ft.commit(); 

    } 

    @Override 
    protected void onStart() { 
     super.onStart(); 
     setUpEventSpots(); 
    } 

    private void setUpEventSpots() { 
     // I'm going to make 2 EventInfo objects and place them on the map 
     EventInfo firstEventInfo = new EventInfo(new LatLng(50.154, 4.35), 
       "Right now - event", new Date(), "Party"); 
     EventInfo secondEventInfo = new EventInfo(new LatLng(51.25, 4.15), 
       "Future Event", new Date(1032, 5, 25), "Convention"); 

     EventInfo thirdEventInfo = new EventInfo(new LatLng(23.25, 72.15), 
       "Our Next Event", new Date(), "Ahmedabad-India"); 
     // this date constructor is deprecated but it's just to make a simple 
     // example 

     Marker firstMarker = mapFragment.placeMarker(firstEventInfo); 
     Marker secondMarker = mapFragment.placeMarker(secondEventInfo); 
     ThirdMarker = mapFragment.placeMarker(thirdEventInfo); 
     eventMarkerMap = new HashMap<Marker, EventInfo>(); 
     eventMarkerMap.put(firstMarker, firstEventInfo); 
     eventMarkerMap.put(secondMarker, secondEventInfo); 
     eventMarkerMap.put(ThirdMarker, thirdEventInfo); 

     // add the onClickInfoWindowListener 
     mapFragment.getMap().setOnInfoWindowClickListener(
       new OnInfoWindowClickListener() { 

        @Override 
        public void onInfoWindowClick(Marker marker) { 
         EventInfo eventInfo = eventMarkerMap.get(marker); 
         Toast.makeText(
           getBaseContext(), 
           "The date of " 
             + eventInfo.getName() 
             + " is " 
             + eventInfo.getSomeDate() 
               .toLocaleString(), 
           Toast.LENGTH_LONG).show(); 

        } 
       }); 



     // Custom Bhavesh 
     mapFragment.getMap().setInfoWindowAdapter(new InfoWindowAdapter() { 

      private final View window = getLayoutInflater().inflate(
        R.layout.ballonoverlly, null); 

      @Override 
      public View getInfoWindow(Marker marker) { 
       EventInfo eventInfo = eventMarkerMap.get(marker); 

       String title = marker.getTitle(); 
       TextView txtTitle = ((TextView) window 
         .findViewById(R.id.textview_name)); 
       if (title != null) { 
        // Spannable string allows us to edit the formatting of the 
        // text. 
        SpannableString titleText = new SpannableString(title); 
        titleText.setSpan(new ForegroundColorSpan(Color.RED), 0, 
          titleText.length(), 0); 
        txtTitle.setText(titleText); 
       } else { 
        txtTitle.setText(""); 
       } 

       // TextView txtType = ((TextView) window 
       // .findViewById(R.id.textview_aboutme)); 
       // if (eventInfo.getType() != null) 
       // txtType.setText(eventInfo.getType()); 

       return window; 
      } 

      @Override 
      public View getInfoContents(Marker marker) { 
       // this method is not called if getInfoWindow(Marker) does not 
       // return null 
       return null; 
      } 
     }); 
    } 

} 

XML 파일 : 내가 원하는, 이제 enter image description here

: 아래

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RlMain" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 


    <LinearLayout 
     android:id="@+id/imageview_comment" 
     android:layout_width="150dp" 
     android:layout_height="62dp" 
     android:background="@drawable/map_comment_back" 
     android:gravity="center_vertical" 
     android:orientation="vertical" 
     android:scaleType="fitXY" 
     android:visibility="visible" > 

     <TextView 
      android:id="@+id/textview_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      android:text="Bhavesh Patadiya" 
      android:textColor="#FFFFFF" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/textview_aboutme" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      android:maxLines="2" 
      android:text="How&apos;s Going?" 
      android:textColor="#FFFFFF" 
      android:textStyle="normal" /> 
    </LinearLayout> 
</LinearLayout> 

내가 얻고 무엇의 스크린 샷입니다 아래

은 내가 사용하고있는 코드입니다 Top 대신 Marker의 오른쪽에 사용자 정의 InfoWindow가 있어야합니다.

모든 도움이 감사드립니다.

미리 감사드립니다.

+0

다음과 같이 시도해보십시오. u ->에 따라 왼쪽 절반 공백 및 절반 오른쪽을 이미지 (배경)로 만든 다음 오른쪽 부분에 내용 (TextView)을 추가하십시오. 왼쪽면이 공백으로 보이기 때문에 마커의 오른쪽을 차지할 수 있기를 바랍니다. – Maddy

답변

0

당신은 코드를 아래와 같이 screenPosition에) 간단한 변환 marker.getPosition (가 할 수있는

Projection projection = map.getProjection(); 
LatLng markerLocation = marker.getPosition(); 
Point screenPosition = projection.toScreenLocation(markerLocation); 

int x = screenPosition.x +marker. markerImage.getWidth(); 
당신은 (투사하는 getPosition 변환) 더 많은 정보]에 대한 아래 링크를 심판 할 수

:

How to get screen coordinates from marker in google maps v2 android

+0

@BhaveshPatadiya, 이것으로 끝났습니까? Info Window를 화면 맨 위에 놓으려고합니다. – andrefadila

+0

어떻게지도에 뷰를 올릴 수 있습니까? 'inflater.inflate (R.id.overlay_layout, (viewGroup) myViewGroup) '코드를 사용하여 맵에 조각을 배치 할 때 마커에서 뷰를 표시하지만 내 레이아웃은 레이아웃이 측면을 따라있을 때 화면보기의 wraped 가져옵니다 즉 textview textview1 텍스트가있는 경우 일부 텍스트를 한 줄 및 일부 텍스트를 두 번째 line.Can이 해결하기 위해 나를 도울 수 있습니다. – JAPS

6

편집 2 :

9 월 업데이트 (v12 또는 3.2.65)부터 Google Maps Android API v2 MarkerOptions.infoWindowAnchor가 추가되었습니다. 꽤 많은 새로운 기능이 있으므로 release notes도 확인하십시오.

편집 3 :

이 Unfortunatelly이 또한 아직 문제가 해결되지 않습니다. 그것에 대해 new issue을 추가했습니다.


이것은 현재 불가능합니다.

사용자가지도를 이동할 수없는 경우에 View을 입력하여 해결하려면 좋은 해결책이 될 수 있습니다. 가능한 경우 "푸시 기술"onCameraChange을 사용하거나 Handlermap.getCameraPosition()을 사용하여 폴링하는 경우 위치를 바꿀 때 약간의 시차가 발생할 수 있습니다.

투명 아이콘이있는 추가 마커를 사용하여 표시가 클릭되었을 때 정보창을 표시하려고하면 동일한 문제가 발생하지만 실제로 구현 된 것을 보는 것이 더 재미있을 것입니다.

지금 당장 정보 창이 없으면 살 수있는 경우, this feature already requested 주연 및 대기 중입니다.

편집 : 3.1.36 (계의로

.7) API v2의 마커 아이콘을 변경할 수 있습니다. 즉, 오른쪽에 정보 창이 열려있는 것과 같이 보통 아이콘 하나와 다른 아이콘 아이콘 두 개를 만들 수 있습니다. 기본 정보 창을 열지 않고 대신이 기능을 사용하면 도움이 될 수 있습니다.