2013-08-28 2 views
6

처음으로 사용자가지도를 볼 때 확대/축소 및 카메라 설정으로 마커를 표시 할 수 있습니다. 그러나 사용자가 방문하는 동안 마커 위치 (마커가 화면에 표시되지 않음)에서 벗어나면 동일한 마커 위치로 카메라를 이동해야합니다 (사용자가 원하는 경우).Google지도의 특정 마커로 안드로이드의 특정 마커로 이동하는 방법

+0

코드 -을 : 나는 코드 아래 사용이지도 API의 최신 업데이트 작업이 (setOnMyLocationButtonClickListener을 가지고) 있어요? –

답변

9

답장을 보내 주셔서 감사합니다. 하지만 일부 기본지도 compo를 찾고있었습니다. 외부 마커 대신 맵 마커 재설정 작업을 수행하여 원하는 마커 위치로 돌아갈 수 있습니다. .....

mMap.setMyLocationEnabled(true); 
    LatLng markerLoc=new LatLng(companyDetail.getLatitude(), companyDetail.getLongitude()); 
    final CameraPosition cameraPosition = new CameraPosition.Builder() 
    .target(markerLoc)  // Sets the center of the map to Mountain View 
    .zoom(13)     // Sets the zoom 
    .bearing(90)    // Sets the orientation of the camera to east 
    .tilt(30)     // Sets the tilt of the camera to 30 degrees 
    .build();     // 
    mMap.addMarker(new MarkerOptions().position(new LatLng(companyDetail.getLatitude(), companyDetail.getLongitude())).title("Marker")); 
    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 
    mMap.setOnMyLocationButtonClickListener(new OnMyLocationButtonClickListener() { 
     @Override 
     public boolean onMyLocationButtonClick() { 
      mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); 
      return true; 
     } 
    }); 
16

(당신은 줌의 원하는 수준의 "14"를 대체 할 경우)를 GoogleMap으로 개체 및 마커에 대한 참조, 당신은 단순히

GoogleMap mMap; 
Marker mMarker; 

[...] 

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mMarker.getPosition(), 14)); 

을 사용할 수 있습니다 가졌어요.

사용자가 클릭하여 마커로 돌아가려면 클릭하는 버튼의 OnClick 이벤트에 해당 라인을 첨부하기 만하면됩니다! ;)

5

당신은

GoogleMap googleMap = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map).getMap(); 

googleMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition())); 


    [1]: https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap#animateCamera%28com.google.android.gms.maps.CameraUpdate%29 
2

당신은 또한 다음과 같이 사용할 수 있습니다 GoogleMap으로 개체의 [animateCamera] [1] 기능을 사용할 수 있습니다 :

LatLng cur_Latlng=new LatLng(21.0000,78.0000); // giving your marker to zoom to your location area. 
gm.moveCamera(CameraUpdateFactory.newLatLng(cur_Latlng)); 
gm.animateCamera(CameraUpdateFactory.zoomTo(4)); 

// 다른 방법은 현재 위치를 사용하는 것입니다

@Override 
public void onLocationChanged(Location location) { 

LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); 

CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 4); 

gm.animateCamera(cameraUpdate); 

Marker myMarkerthirtyfour = gm.addMarker(new MarkerOptions() 

.position(latLng) 

.title("You are here") 

.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))); 

locationManager.removeUpdates(this); 

    } 
관련 문제