I want build a android map application and Launch app will got null from SupportMapFragment(said my supportMapFragment is null), if you can point me where is my mistake, please help, many thanks.
code, XML and manifest as below.
By the way, the MapFragment is come from BottomNavigationView tab
R.id.navigation_map -> {
val mapFragment = MapFragment()
mapFragment.setArguments(intent.extras)
supportFragmentManager.beginTransaction()
.add(R.id.fragment_container, mapFragment).commit()
return#OnNavigationItemSelectedListener true
MapFragment.java
public class MapFragment extends Fragment implements OnMapReadyCallback {
private View rootView;
private AppCompatActivity context;
private SupportMapFragment supportMapFragment;
private GoogleMap map;
public MapFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
rootView = inflater.inflate(R.layout.fragment_map, container, false);
context = (AppCompatActivity) getActivity();
supportMapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.fragmentmap);
if (supportMapFragment != null) {
supportMapFragment.getMapAsync(this);
getFragmentManager().beginTransaction()
.replace(R.id.fragment_container, supportMapFragment).commit();
} else {
Toast.makeText(context, "Error - Map Fragment was null!!", Toast.LENGTH_SHORT).show();
}
return rootView;
}
#Override
public void onMapReady(GoogleMap googleMap) {
}
}
fragment_map.xml
<android.support.design.widget.CoordinatorLayout
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"
android:fitsSystemWindows="true">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragmentmap"
tools:context=".MainActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</android.support.design.widget.CoordinatorLayout>
Manifests
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
</application>
If you are using fragment inside another fragment then better to use getChildFragmentManager as it return a private FragmentManager for placing and managing Fragments inside of this Fragment.
supportMapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.fragmentmap);
Reference: getChildFragmentManager
Related
I am trying to build a location based MAP app and when I try to execute my App, I can view my Markers added to the Mapsactivity, however i don't Map on the activity
I can confirm that I have provide the correct Map key for my activity getting the key from console.developer.com and enabling Google Maps for Android API
Please suggest what could be wrong here
MapsActivity
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private final String TAG = "MapActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
Log.d(TAG, "inside create Fragment");
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Log.d(TAG, "outside create Fragment");
}
#Override
public void onMapReady(GoogleMap map) {
SharedPreferences preferences= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Double mLat = Double.parseDouble(preferences.getString("latitude",""));
Double mLon = Double.parseDouble(preferences.getString("longtitude",""));
Log.d(TAG, preferences.getString("latitude",""));
Log.d(TAG, preferences.getString("longtitude",""));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mLat,mLon), 20));
map.addMarker(new MarkerOptions().position(new LatLng(mLat,mLon)));
//map.setMyLocationEnabled(true);
}
}
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<activity android:name=".MyGames"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key"/>
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.wesport.MainActivity"/>
</activity>
</application>
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=".MapsActivity"/>
Image from the emulator
Probably you show desert on the map.
Try change:
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mLat,mLon), 20));
to
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(mLat, mLon), 5));
When I add map fragment:
<fragment 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"
android:id="#+id/map"
tools:context=".MainActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
to activity_main.xml I get that error:
FATAL EXCEPTION: main
Process: com.example.koba.ogloszenia, PID: 3073
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.koba.ogloszenia/com.example.koba.ogloszenia.MainActivity}: android.view.InflateException: Binary XML file line #120: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
...
My MainActivity.java:
public class MainActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment MapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
MapFragment.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap Map) {
mMap = Map;
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
My AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.koba.ogloszenia">
<uses-permission android:name="android.Manifest.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.Manifest.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.Manifest.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="MY_API_KEY"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I have included in depedencies
com.google.android.gms:play-services:9.2.1
and
com.google.android.gms:play-services-maps:9.2.1
I also have checked "Google Play services" in SDK Tools.
I also looked similar posts but that didn't solve my problem.
Thank you in advance.
The <meta-data> elements must be within the <application> element of your AndroidManifest.xml but out of the <activity> element.
I'm trying to make an app with a button called "Map" that will display a city map once pressed. So far I've made an app which contains the Map button and a separate app for my map which uses the Google Developers' tutorial to display a map when the app is opened. I'm having trouble when I try to combine both apps. I'm working on the OnClickListener but I don't know what I should put so that the map would be displayed after pressing the button.
EDIT
Below is my MapFragment class for the map:
public class MapFragment extends FragmentActivity
{
private GoogleMap mMap;
private LatLngBounds ILOILO = new LatLngBounds(new LatLng(10.6, 122.466), new LatLng(10.716, 122.566));
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.map_layout, container, false);
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMyLocationEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(ILOILO.getCenter(), 10));
if (mMap == null)
{
Toast.makeText(this, "Google Maps not available",
Toast.LENGTH_LONG).show();
}
return v;
}
}
Here's my XML file for the map:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
map:uiCompass="false"
map:uiTiltGestures="true"
map:uiZoomControls="true"
map:uiZoomGestures="true"
map:uiRotateGestures="true"
map:uiScrollGestures="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
Here's for the button located in my MainActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageButton mapButton = (ImageButton) findViewById(R.id.mapButton);
mapButton.setOnClickListener(mapListener);
}
private OnClickListener mapListener = new OnClickListener()
{
public void onClick(View v)
{
Intent i = new Intent(MainActivity, MapFragment.class);
startActivity(i);
}
};
I've also modified my Manifest since I've been getting "Unable to find explicit activity class (com.example.ipp.MapFragment); have you declared this activity in your AndroidManifest.xml?" error. Below is my manifest.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="MapFragment" >
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
PROBLEM
When I try to click the "Map" button, it displays my UI instead of displaying the map I've prepared.
i can show plain guide in inside part i have to add marker to specific geolocation
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="100dp"
android:name="com.google.android.gms.maps.SupportMapFragment"
/>
I don't did anything in java code however i extended my class with Fragment
Don't forget to add google-play-service-lib as a library project and
it should sharing the same workspace of your project
Java code
public class SomeFragment extends Fragment {
MapView mapView;
GoogleMap map;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.some_layout, container, false);
// Gets the MapView from the XML layout and creates it
mapView = (MapView) v.findViewById(R.id.mapview);
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
// Needs to call MapsInitializer before doing any CameraUpdateFactory calls
try {
MapsInitializer.initialize(this.getActivity());
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
// Updates the location and zoom of the MapView
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
map.animateCamera(cameraUpdate);
return v;
}
#Override
public void onResume() {
mapView.onResume();
super.onResume();
}
#Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}
Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.gms.maps.MapView android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.example.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="your_key"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".HomeActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Edit: After your edit new question arise.
After initializing map check if it is not null from official documentation
if(map != null)
{
Marker marker = map.addMarker(new MarkerOptions()
.position(new LatLng(37.7750, 122.4183))
.title("San Francisco")
.snippet("Population: 776733"));
}
In your layout, replace your code with this one :
<RelativeLayout
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="100dp">
</RelativeLayout>
and in your code :
private SupportMapFragment supportMapFragment;
private GoogleMap map;
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
FragmentManager fm = getChildFragmentManager();
supportMapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
if (supportMapFragment == null) {
supportMapFragment = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.map, supportMapFragment).commit();
}
}
#Override
public void onResume() {
super.onResume();
...
map = supportMapFragment.getMap();
...
}
In my app i showing google map version2 in a fragment. but i get Null pointer exception
at
mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
This is my full code:
public class SearchResultMap extends Fragment{
private GoogleMap mMap;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View fragmentView = inflater.inflate(R.layout.map, container, false);
mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); // line no : 28
mMap.addMarker(new MarkerOptions() .position(new LatLng(xxxxxx,xxxxxx)) .title("Current Location")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ball_pointer))
.snippet("xxxxx"));
return fragmentView;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Manifest xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fssd.spot"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.fssd.spot.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.fssd.spot.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.fssd.spot.SplashScreen"
android:theme="#android:style/Theme.Light.NoTitleBar"
android:noHistory="true"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.fssd.spot.MainActivity"
android:screenOrientation="portrait"
android:theme="#style/tabTheme" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxxxxxx" />
</application>
</manifest>
whole log cat:
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.fssd.spot.search.SearchResultMap.onCreateView(SearchResultMap.java:28)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
at android.support.v4.app.Fragment.performStart(Fragment.java:1499)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:957)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
at dalvik.system.NativeStart.main(Native Method)
None of these solutions fixed it for me -- but this answer from Mark Murphy (https://code.google.com/p/android/issues/detail?id=77714) did:
Use getChildFragmentManager() to access a nested fragment, not getFragmentManager(). http://developer.android.com/reference/android/support/v4/app/Fragment.html#getChildFragmentManager%28%29
i.e.:
public class MapFragment extends Fragment {
private GoogleMap map;
private SupportMapFragment mapFragment;
...
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup vg, Bundle data) {
View view = inflater.inflate(R.layout.map_view, vg, false);
FragmentManager fm = getChildFragmentManager();
mapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
mapFragment.getMapAsync(new OnMapReadyCallback() {
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
initMap();
}
});
}
}
try to change this:
FragmentManager myFM = getActivity().getSupportFragmentManager();
final SupportMapFragment myMAPF = (SupportMapFragment) myFM
.findFragmentById(R.id.map);
Try changing to
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
You're using getFragmentManager(), but casting it to SupportMapFragment
You also need to extend FragmentActivity: http://developer.android.com/reference/android/support/v4/app/FragmentActivity.html
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
if(map != null) {
mMap.addMarker(new MarkerOptions() .position(new LatLng(xxxxxx,xxxxxx)) .title("Current Location")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ball_pointer))
.snippet("xxxxx"));
}
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxxxxxx" />
place your google api key here. You get from google Read the documentation.
After hours of search, I did in this way:
public class MapFragment extends Fragment {
private GoogleMap map;
SupportMapFragment mapFrag;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
setHasOptionsMenu(true);
View rootView = inflater.inflate(R.layout.fragment_map, container,
false);
fm = getActivity().getSupportFragmentManager();
map = ((SupportMapFragment) fm.findFragmentById(R.id.map)).getMap();
return rootView;
}
}
Try to add tools:context=".YourActivity" to the fragment xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
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=".YourActivity" />
May be above answers work but what work for me is this.
{
SupportPlaceAutocompleteFragment supportPlaceAutocompleteFragmentSearch;
FragmentManager fragmentManagerSearch = getChildFragmentManager();
supportPlaceAutocompleteFragmentSearch =
(SupportPlaceAutocompleteFragment)
fragmentManagerSearch.findFragmentById(R.id.place_autocomplete_fragment_search);
}
if you developed your code with Kotlin, and want to add MapFragment to another Fragment you need to use SupportMapFragment but if you do it, you will get null exception so you should use childFragmentManager rather than supportFragmentManager and the code should be in onCreateView not in onCreate just add below code:
private lateinit var mapFragment : SupportMapFragment
mapFragment = childFragmentManager.findFragmentById(R.id.mapview) as SupportMapFragment
mapFragment.getMapAsync { googleMap ->
this.googleMap = googleMap
setGoogleMapSettings()
}