Ich habe eine Karte Fragment erstellt, das wie folgt aussieht:Google Maps keine Gesten arbeiten
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" />
Und ich rufe das folgende Fragment aus einer Aktivität:
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();
}
}
Und die folgende xml ist der Inhalt von 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>
Ich sehe die Kartenansicht, es funktioniert gut. Das einzige Problem ist, dass ich die Karte nicht ziehen kann, um andere Orte zu sehen oder die Karte zu zoomen.
Ich habe das Google Maps-Aktivitätsmodell verfolgt. Als ich die MapsActivity (von Google angeboten) gestartet habe, war alles in Ordnung. Das einzige, was ich geändert habe, war, MapsActivity zu einem Fragment zu machen. Ich habe versucht mit googleMap.getUiSettings().setAllGesturesEnabled(true);
, aber es hat nicht funktioniert.