У меня есть проблема, которую я пишу в заголовке
Вот 2 кода из MapsActivity и фрагмент
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
map.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// redraw the marker when get location update.
LatLng latlng = new LatLng(location.getLatitude(), location.getLongitude());
map.addMarker(new MarkerOptions().position(latlng).title("Marker").snippet(Float.toString(location.getSpeed())));
map.moveCamera(CameraUpdateFactory.newLatLng(latlng));
}
};
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 15, locationListener);
}
}
Карта фрагментов
public class Tab2Map extends Fragment implements OnMapReadyCallback {
GoogleMap map;
public Tab2Map() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.fragment_tab2, container, false);
return v;
}
@Override
public void onViewCreated(View view,@Nullable Bundle savedInstanceState){
super.onViewCreated(view,savedInstanceState);
SupportMapFragment mapFragment=(SupportMapFragment)getChildFragmentManager().findFragmentById(R.id.fragment);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
}
}
Как можноЯ поместил маркер из MapsActivity во фрагмент, потому что это единственный способ напечатать его на карте. В приложении есть вкладки «Панель действий», и карту можно отобразить только через фрагмент?