Adding google map (fragment?) to activity

google map inside fragment android example
google maps api
google map in fragment kotlin
google map activity
how to use google map in android programmatically
google maps implementation
google map'' android
google map types android

I'm trying to add a map fragment to an activity much like the get started guide: https://developers.google.com/maps/documentation/android-sdk/start

My problem is that the app just quits the moment it's run. So for the relevant parts of the MainActivity.java file:

import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

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 googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

Also the (hopefully relevant parts) of activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <fragment
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="363dp"
        android:layout_height="252dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        map:layout_constraintEnd_toEndOf="parent"
        map:layout_constraintStart_toStartOf="parent"
        map:layout_constraintTop_toBottomOf="@+id/rcv"
        tools:context=".MainActivityy" />



</androidx.constraintlayout.widget.ConstraintLayout>

Apart from this i have also created "google_maps_api.xml" in the values folder (real api redacted):

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">MYGOOGLEAPI</string>

</resources>

I've managed to verify my api working through following the previously linked example to the letter, in my own application it does not work at all however.

I've managed to identify the following error in "logcat":

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #78 in com.example.myapplication:layout/activity_main: Binary XML file line #78 in com.example.myapplication:layout/activity_main: Error inflating class fragment

Thus to my understanding my problem lies in the activity_main.xml file, what it means or how to solve it puzzles me unfortunatly. Any help is greatly appreciated. Just to clearify, line 78 is hte line of "

Another idea is that i perhaps have to initialise/declare it like a widget?

including full Logcat in case prevously mentioned is nothing critical:

2019-10-08 20:45:20.514 7610-7610/? E/e.myapplicatio: Unknown bits set in runtime_flags: 0x8000
2019-10-08 20:45:21.717 7610-7610/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myapplication, PID: 7610
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #78 in com.example.myapplication:layout/activity_main: Binary XML file line #78 in com.example.myapplication:layout/activity_main: Error inflating class fragment
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: android.view.InflateException: Binary XML file line #78 in com.example.myapplication:layout/activity_main: Binary XML file line #78 in com.example.myapplication:layout/activity_main: Error inflating class fragment
     Caused by: android.view.InflateException: Binary XML file line #78 in com.example.myapplication:layout/activity_main: Error inflating class fragment
     Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
        at com.google.maps.api.android.lib6.drd.p.b(:com.google.android.gms.dynamite_mapsdynamite@17786052@17.7.86 (040700-256199907):22)
        at com.google.maps.api.android.lib6.auth.d.a(:com.google.android.gms.dynamite_mapsdynamite@17786052@17.7.86 (040700-256199907):10)
        at com.google.maps.api.android.lib6.impl.d.a(:com.google.android.gms.dynamite_mapsdynamite@17786052@17.7.86 (040700-256199907):41)
        at com.google.android.gms.maps.internal.CreatorImpl.a(:com.google.android.gms.dynamite_mapsdynamite@17786052@17.7.86 (040700-256199907):61)
        at com.google.android.gms.maps.internal.CreatorImpl.newMapFragmentDelegate(:com.google.android.gms.dynamite_mapsdynamite@17786052@17.7.86 (040700-256199907):25)
        at com.google.android.gms.maps.internal.h.a(:com.google.android.gms.dynamite_mapsdynamite@17786052@17.7.86 (040700-256199907):73)
        at hp.onTransact(:com.google.android.gms.dynamite_mapsdynamite@17786052@17.7.86 (040700-256199907):4)
        at android.os.Binder.transact(Binder.java:914)
        at com.google.android.gms.internal.maps.zza.zza(Unknown Source:10)
        at com.google.android.gms.maps.internal.zzf.zzc(Unknown Source:5)
        at com.google.android.gms.maps.SupportMapFragment$zzb.zzd(Unknown Source:12)
        at com.google.android.gms.maps.SupportMapFragment$zzb.createDelegate(Unknown Source:6)
        at com.google.android.gms.dynamic.DeferredLifecycleHelper.zaa(Unknown Source:18)
        at com.google.android.gms.dynamic.DeferredLifecycleHelper.onInflate(Unknown Source:20)
        at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source:21)
        at androidx.fragment.app.Fragment.onInflate(Fragment.java:1384)
        at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3744)
        at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:120)
        at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:405)
        at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:387)
        at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
2019-10-08 20:45:21.718 7610-7610/com.example.myapplication E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:438)
        at android.app.Activity.setContentView(Activity.java:3324)
        at com.example.myapplication.MainActivity.onCreate(MainActivity.java:40)
        at android.app.Activity.performCreate(Activity.java:7802)
        at android.app.Activity.performCreate(Activity.java:7791)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)


Try to add google map api key inside tag in android manifest file.

<application>
    //...
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="YOUR_API_KEY"/>
    //...
</application>

Map Objects | Maps SDK for Android, https://developers.google.com › com › google › android › gms › maps This fragment is the simplest way to place a map in an application. It's a wrapper around a view of a map to automatically handle the necessary life cycle needs. Being a fragment, this component


Try to add your Google Maps API Key to your AndroidManifest.xml as suggested in the stack trace in the following line:

Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml

Map Fragment in, If you meant to ask something like you have a fragment A in an activity,and a map fragment say B from A.(Do you want to open it in the same activity or You may know that Google is tracking you, but most people don't realize the extent of it. fragment or any other way to add sub menu inside the fragment in Android? Add code. Replace getSupportFragmentManager() used in a Activity to getChildFragmentManager() used in a Fragment. Remove findFragmentById code (previosly inflated by layout using <Fragment>). Create SupportMapFragment instance manually and replace R.id.map layout with SupportMapFragment instance by using FragmentTransaction.


Add meta data with your generated API key In your manifest file with the API key you have generated.

How to open map in map fragment inside another fragment in , Add Google Play Services to Android Studio and to your project using the following guide from our friends Navigate to New->Google->Google Maps Activity. b. I have a problem integrating google map in fragment in android. I know how to do it in activity but fragment reference on this site are very old and not working in 2018.


[PDF] Google Map Fragment Tutorial Setup Your Project to Use Google , On the Add an Activity to Mobile view, select the Google Maps Activity and click Next. SupportMapFragment import com.google.android.gms.maps.model. GoogleMap override fun onCreate(savedInstanceState: Bundle?) Many developers want to use Ionic Google Maps to add mapping and geolocation to their applications. With Google Maps Android API v2, you can embed maps into an activity as a fragment with a simple XML snippet. Also explained important things like getting latitude and longitude of location, placing marker on the map etc,.


Introduction to Google Maps API for Android with Kotlin , LISTING 15-22: Adding a Support Map Fragment to your layout <fragment 15-​23: Accessing a Google Map within your Activity import android.support.v4.app. The MapFragment object is used to place a map within an Android Fragment, so that you can reuse the Fragment across multiple activities. One caveat is that the MapFragment requires APL level 12 or higher, so if you intend to support earlier APIs, the same functionality is available through the SupportMapFragment.


Professional Android, tools:openDrawer="start">. <include. android:id="@+id/included_layout" override fun onMapReady(p0: GoogleMap?) {. map = p0. val uiSettings = map? By using this code we can setup MapView anywhere, inside any ViewPager or Fragment or Activity. In the latest update of Google for Maps, only MapView is supported for fragments. MapFragment & SupportMapFragment doesn't work. I might be wrong but this is what I saw after trying to implement MapFragment & SupportMapFragment.