2017-12-28 11 views
1

작업에는 제스처를 매핑하지 다음구글은 내가처럼 보이는지도 조각을 만든

public class MapsFragment extends Fragment implements OnMapReadyCallback { 

    private GoogleMap mMap; 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
     super.onCreateView(inflater, container, savedInstanceState); 
     return inflater.inflate(R.layout.activity_maps, container, false); 
    } 

    @Override 
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 
     super.onViewCreated(view, savedInstanceState); 
     SupportMapFragment supportMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map); 
     supportMapFragment.getMapAsync(this); 
    } 

    @Override 
    public void onMapReady(final GoogleMap googleMap) { 
     mMap = googleMap; 
     googleMap.getUiSettings().setZoomGesturesEnabled(true); 
     mMap.getUiSettings().setZoomGesturesEnabled(true); 
     final LatLng latlg = new LatLng(40.730610, -73.935242); 
     mMap.addMarker(new MarkerOptions().position(latlg)); 
     mMap.moveCamera(CameraUpdateFactory.newLatLng(latlg)); 
     mMap.animateCamera(CameraUpdateFactory.zoomTo(12.0f)); 


    } 
} 

activity_maps.xml :

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:map="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/map" 
android:name="com.google.android.gms.maps.SupportMapFragment" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="tagonsoft.com.kidgonet.gui.fragments.MapsFragment" /> 

그리고 활동에서 다음 조각을 호출

public class MyActivity extends AppCompatActivity { 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      Fragment mFragment = null; 
      mFragment = new MapsFragment(); 
      FragmentManager fragmentManager = getSupportFragmentManager(); 
      fragmentManager.beginTransaction() 
        .replace(R.id.fragment_overview, mFragment).commit(); 
      }   
    } 

다음 xml은 MyActivity의 내용입니다.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
<FrameLayout 
     android:id="@+id/fragment_overview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
    /> 
</RelativeLayout> 

지도보기가 표시됩니다. 정상적으로 작동합니다. 유일한 문제는지도를 드래그하여 다른 장소를 보거나지도를 확대 할 수 없다는 것입니다.

나는 Google의지도 활동 모델을 따라 갔다. Google에서 제공 한 MapsActivity를 시작했을 때 모든 것이 괜찮 았습니다. 필자가 변경 한 유일한 방법은 MapsActivity를 조각화하는 것입니다. googleMap.getUiSettings().setAllGesturesEnabled(true);으로 시도했지만 작동하지 않았습니다.

답변

0

나는이 문제를 발견했다. 위의 코드가 올바르게 작동합니다. 그것은 내 실수였습니다. 탐색 서랍도 구현했습니다. 탐색 서랍이지도보기 위에 있었기 때문에지도 드래그 나 제스처에 액세스 할 수 없었습니다.