2014-05-25 3 views
5

구글 맵에 버튼이있는 InfoWindow를 가지고 있는데, chose007의 해킹을 시도해 볼 수있는 변형을 시도하고 있습니다 (이 question 참조).지도의 InfoWindow보기의 화면 좌표를 얻는 방법

내 접근 방식은 InfoWindow 내부 버튼의 화면 좌표를 가져와 onDispatchTouchEvent 함수로 조작하는 것에 의존합니다.

그러나 화면 좌표를 가져 오는 모든 시도가 실패합니다. 즉, 내가 만든 후 onDispatchTouchEvent (즉, 만든 후) 호출하고 있지만 버튼과보기 모두에 대해 0,0을 얻습니다.

InfoWindow가 특별한 경우이고 실제 UI 요소가 아니기 때문에 이것이라고 가정합니다. (IIRC 전체보기는 기본적으로지도 상단에 블 리트되는 비트 맵입니다.) 좌표를 가져올 방법이 있습니까? 나는 chose007의 해결책처럼 매직 넘버를 포함하는 것을 피하려고 노력하고 있다고 언급해야합니다. 여기

내가 뭘하는지의 단순화 된 그림이다 : 그건 당신이 버튼이 정말 정의 정보창을 만들기 위해 사용되어야 하는지를 아니기 때문에

public boolean onDispatchTouchEvent(MotionEvent ev) { 
    int[] location = new int[2]; 
    mTestButton.getLocationOnScreen(location); // Returns 0,0 
    mTestView.getLocationOnScreen(location); // Returns 0,0 

    return false; 
} 

public View getInfoContents(Marker marker) { 
    LayoutInflater inflater = (LayoutInflater) mContext 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    mTestView = inflater.inflate(R.layout.info_window, null); 
    mTestButton = ((Button) mTestView.findViewById(R.id.test_button)); 
} 
+1

정보창이 그려진 스냅 샷이고 '보기'계층의 일부가 아니라는 가정하에 올바른 것입니다.위치 지정을 얻는 유일한 방법은 chose007의 답변에서 "마커 숫자"를 사용하는 것입니다.이 방법은 기본 앵커 및 회전을 가정하고 '마커'위치와 정보창 크기로 계산합니다. 또한 사용자 지정 앵커 및 회전을 허용하는 일반 [구현] (https://gist.github.com/corsair992/8313269)을 파생 시켰으며 정보창을 터치 리스너를 통해 해킹하지 않고도 라이브로 만들었습니다. 대답에 대한 의견에 – corsair992

+0

마커 좌표에 앵커 된 자신 만의'PopupWindow' 디스플레이를 시도하십시오. –

답변

1

그래서 당신은 정보창에 막 다른 골목을 명중했고 이러한. 이 양키 엔지니어가 그렇게하지는 않을 것입니다.

당신이 뭔가 정의는 사용자가 마커의 좌표로지도를 마커가 다음 마커 클릭이 마커에서보기를 보여 캡처 클릭 중심을 조정하는 경우 표시와onMarkerClick

https://developers.google.com/maps/documentation/android/marker#marker_click_events에서 true을 반환하려면

public boolean onMarkerClick (Marker marker) 

마커를 클릭하거나 두드리면 호출됩니다. 매개 변수 마커 클릭 한 마커. Returns

리스너가 이벤트를 소비 한 경우 (즉, 기본 비헤이비어가 발생하지 않아야하는 경우) true이고, 그렇지 않으면 false입니다 (기본 비헤이비어가 발생해야 함). 기본 동작은 카메라가지도로 이동하고 정보 창이 표시되는 것입니다.

그래서 어떻게하면 정보창 모양을 취하는지도 위에 무엇을 넣을 수 있습니까? 나는 잘라내어 붙여 넣기 작업을 한 소스에서 쉽게 사용할 수있는 이미지가 아닌 멋진 이미지를 필요로합니다. 이리.

지도 위에 어떻게 단추를 놓을까요? 음,이 예제에서는 단추가 정적 위치에 있습니다. Pseudo infowindow를 사용하면 버튼이나 이미지를 마커의 좌표로 이동하고 마커 좌표에지도를 중앙에 배치해야합니다.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" > 

    <fragment 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     class="com.google.android.gms.maps.SupportMapFragment" /> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="32dp" 
     android:layout_marginTop="34dp" > 

     <TextView 
      android:id="@+id/tvSpeed" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@color/black" 
      android:textSize="55sp" /> 

     <TextView 
      android:id="@+id/tvSpeedUnits" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@color/black" 
      android:textSize="21sp" /> 
    </LinearLayout> 

    <Button 
     android:id="@+id/btnFollow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="34dp" 
     android:background="@drawable/mapbutton" 
     android:padding="14dp" 
     android:text="@string/btnFollowText" 
     android:textColor="@color/black" /> 

    <TextView 
     android:id="@+id/tvSatLock" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:text="sat lock" 
     android:textColor="@color/black" 
     android:textSize="21sp" /> 

    <Button 
     android:id="@+id/btnGPS" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:background="@drawable/mapbutton" 
     android:paddingLeft="14dp" 
     android:paddingRight="14dp" 
     android:text="Enable GPS" 
     android:textColor="@color/black" /> 

</RelativeLayout> 

개인적으로 infowindow를 클릭하면 전체 화면에 디럭스 투명 오버레이가 표시됩니다. 나는 사용자가 당신이가는 어떤 방법을 클릭해야한다는 것을 의미한다.

행운을 빌어 요 부호가있는 하나 infoWindow 수신기보다 먼저 클릭하십시오.

관련 문제