2011-11-19 2 views
13

맵 마커가 맵에 추가되면 애니메이션을 적용하고 싶습니다.마커를 Android에서지도에 추가 할 때 마커를 움직이게하는 방법은 무엇입니까?

사용자는 주변에 마커가있는지도를보아야합니다. 각 새 마커가 튀어 나와야합니다.

+1

사용 MapOverlay 및 마커를 팽창하는 프레임 레이아웃 다음 이미지보기 오브젝트는지도 활동이에 애니메이션을 시작하세요. – Noby

+0

이 링크는 귀하의 질문에 대한 답변이라고 생각합니다 : http : // stackoverflow.co.kr/questions/7407475/can-i-use-animation-drawable-in-an-overlay-on-a mapview –

답변

0

당신은지도 표시로지도보기 어떤 새로운 레이아웃을 추가 할 수 있습니다

public void AddAnimMarkerToMap(MapView map, GeoPoint geoPoint, int id, int animResId) 
{ 
    var layoutParams = new MapView.LayoutParams(ViewGroup.LayoutParams.WrapContent, 
               ViewGroup.LayoutParams.WrapContent, 
               geoPoint, 
               MapView.LayoutParams.Center); 

    var ll = new LinearLayout(map.Context) { Id = id, Orientation = Orientation.Vertical }; 
    ll.SetGravity(GravityFlags.Center); 

    var iv = new ImageView(map.Context); 
    iv.SetImageResource(animResId); 

    ll.AddView(iv); 
    map.AddView(ll, layoutParams); 

    var markerAnimation = (AnimationDrawable)iv.Drawable; 
    markerAnimation.Start(); 
    ll.LayoutParameters = layoutParams; 
} 

아마 직접 레이아웃을 wraping없이 이미지 뷰를 추가 할 수 있습니다. animResId는 프레임 애니메이션 드로어 블 리소스입니다 (Android Mylocation 마커와 유사).

http://developer.android.com/guide/topics/resources/animation-resource.html#Frame

12

당신은 onMarkerClick()을 구현할 수있는 그 위에 마커 바운스 할 때마다 사용자가 클릭을합니다. 코드 구현을 시도해보십시오. 나는 그것을 시도하고 완전히 잘 작동합니다.

private Marker mPerth; 
private Marker mPerth = mMap.addMarker(new MarkerOptions() 
      .position(PERTH) 
      .title("Perth") 
      .snippet("Population: 1,738,800"));   

@Override 
public boolean onMarkerClick(final Marker marker) 
    { 
     // This causes the marker at Perth to bounce into position when it is clicked. 
    if (marker.equals(mPerth)) { 
     final Handler handler = new Handler(); 
     final long start = SystemClock.uptimeMillis(); 
     Projection proj = mMap.getProjection(); 
     Point startPoint = proj.toScreenLocation(PERTH); 
     startPoint.offset(0, -100); 
     final LatLng startLatLng = proj.fromScreenLocation(startPoint); 
     final long duration = 1500; 
     final Interpolator interpolator = new BounceInterpolator(); 
     handler.post(new Runnable() { 
      @Override 
      public void run() { 
       long elapsed = SystemClock.uptimeMillis() - start; 
       float t = interpolator.getInterpolation((float) elapsed/duration); 
       double lng = t * PERTH.longitude + (1 - t) * startLatLng.longitude; 
       double lat = t * PERTH.latitude + (1 - t) * startLatLng.latitude; 
       marker.setPosition(new LatLng(lat, lng)); 
       if (t < 1.0) { 
        // Post again 16ms later. 
        handler.postDelayed(this, 16); 
       } 
      } 
     }); 
    } 
    // We return false to indicate that we have not consumed the event and that we wish 
    // for the default behavior to occur (which is for the camera to move such that the 
    // marker is centered and for the marker's info window to open, if it has one). 
    return false; 
} 

또한 onClick 이벤트 외에 응용 프로그램에서 마커를 추가 할 때이를 사용할 수 있습니다. 나는 당신이 원하는 것만 바랄뿐입니다.

+0

당신은 내 영웅입니다, 고마워요! –

+0

동일한 코드를 시도했지만 라인 오류가 발생했습니다. Interpolator interpolator = new LinearInterpolator(); "호환되지 않는 유형" –

0

시작 위치에서 마커를 고정 시키거나 애니메이션을 시작하십시오. 이 방법에 사용

참고 .setAnchor은 '나는 지금이지도는 데모 엑스트라 샘플을 조정하여 하나 개의 마커를 위해 일하고 있는데 내가 돈 2013년 5월

에서 구글지도 API를 v2로 하였다 이 구현의 성능을 좋아합니다. 가장 중요한 부분은 화면에서 마커를 고정 시키거나 시작 위치에서 꺼내는 것입니다. 위의 화면에서 사용하고 있습니다.

화면에서 마커를 고정합니다 .setAnchor (마커 위의 화면 크기/마커 크기) // 데모 퍼스의 경우 데모 퍼스의 경우 약 6f입니다. 애니메이션을 바꿔 동일한 값으로 바꿉니다. 테스트 폰에서는 6 피트입니다.

private void addMarkersToMap() { 
    // A few more markers for good measure. 
mPerth = mMap.addMarker(new MarkerOptions().position(PERTH) 
      .title("Perth").snippet("Population: 1,738,800") 
      .anchor(.5f, 6f) 
      ); 

변경은 (마커의 마커/크기 위의 화면의 크기) (내 테스트 전화 6 층)에 반사 있도록 애니메이션. 나는 onclick 처리기를 사용하고 있습니다. 이미 6f로 바운스 된 조정 및 더 긴 지속 시간으로 바운스되도록 설정 되었기 때문입니다. 그래서 모든 마커가 맵에 추가 된 후에 나는 클릭 핸들러를 시작합니다.

this.onMarkerClick(mPerth); 

변경된 onMarkerClick 처리기가 6f 이상의 지속 시간을 갖습니다.

@Override 
public boolean onMarkerClick(final Marker marker) { 
    if (marker.equals(mPerth)) { 
     // This causes the marker at Perth to bounce into position when it 
     // is clicked. 
     final Handler handler = new Handler(); 
     final long start = SystemClock.uptimeMillis(); 
     final long duration = 2500; 

     final Interpolator interpolator = new BounceInterpolator(); 

     handler.post(new Runnable() { 
      @Override 
      public void run() { 
       long elapsed = SystemClock.uptimeMillis() - start; 
       float t = Math.max(
         1 - interpolator.getInterpolation((float) elapsed 
           /duration), 0); 

       marker.setAnchor(0.5f, 1.0f + 6 * t); 

       if (t > 0.0) { 
        // Post again 16ms later. 
        handler.postDelayed(this, 16); 
       } 
      } 
     }); 
    } else if (marker.equals(mAdelaide)) { 
     // This causes the marker at Adelaide to change color. 
     marker.setIcon(BitmapDescriptorFactory.defaultMarker(new Random() 
       .nextFloat() * 360)); 
    } 
    // We return false to indicate that we have not consumed the event and 
    // that we wish 
    // for the default behavior to occur (which is for the camera to move 
    // such that the 
    // marker is centered and for the marker's info window to open, if it 
    // has one). 
    return false; 
} 

행운

관련 문제