Java 如何将带有下拉框的谷歌地图添加到片段中
我需要添加一个谷歌地图的下拉列表如下片段 当用户选择下拉列表时,应用程序需要定位位置。我尝试使用android studio中用于MapsActivity的相同代码。我得到了Java 如何将带有下拉框的谷歌地图添加到片段中,java,android,google-maps,android-fragments,google-maps-api-3,Java,Android,Google Maps,Android Fragments,Google Maps Api 3,我需要添加一个谷歌地图的下拉列表如下片段 当用户选择下拉列表时,应用程序需要定位位置。我尝试使用android studio中用于MapsActivity的相同代码。我得到了java.lang.NullPointerException这是我在片段中使用的代码 public class MapFragment extends Fragment implements OnMapReadyCallback { private GoogleMap mMap; public MapFragment(
java.lang.NullPointerException
这是我在片段中使用的代码
public class MapFragment extends Fragment implements OnMapReadyCallback {
private GoogleMap mMap;
public MapFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_map, container, false);
SupportMapFragment mapFragment = (SupportMapFragment) getActivity().getSupportFragmentManager()
.findFragmentById(R.id.googlemap);
mapFragment.getMapAsync(this);
return view;
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(7, 81);
mMap.addMarker(new MarkerOptions().position(sydney).title("Sri Lanka"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
in.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="arimac.dss.lk.dsi.fragments.MapFragment">
<!-- TODO: Update blank fragment layout -->
<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/googlemap"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="arimac.dss.lk.dsi.MapsActivity" />
如何同时添加下拉列表和谷歌地图您希望显示静态地图,或者用户可以与之交互?我需要使用谷歌地图在谷歌地图中使用下拉列表标记一些城市,并提供有关错误的日志,以便社区更好地理解此问题。