0

I have an app that i need to show a mapView inside a fragment like this

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#00838F"
        app:layout_constraintBottom_toTopOf="@+id/middleView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/view3" />

with this code ( onMapReady isn't called )

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)

     mapView.getMapAsync(this)

}
override fun onMapReady(p0: GoogleMap?) {

    Log.d("onMapReady sd","onMapReadyonMapReady")

    googleMap=p0

    //Adding markers to map

    val latLng=LatLng(28.6139,77.2090)

    val markerOptions:MarkerOptions = MarkerOptions().position(latLng).title("New Delhi")

    // moving camera and zoom map

    val zoomLevel = 12.0f //This goes up to 21

    googleMap.let {
        it!!.addMarker(markerOptions)
        it.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoomLevel))
    }

}

and manifest

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="myKeyHere" />

I have created the key in google console under a project with restrict to google maps android and for that package name only , i have tried all possible ways here but i think answers are out-dated ? i didn't supply any billing if this is the reason it doesn't work ?

The map is shown blank with the background color specified in xml with simulator and real device (samsung)

sheko
  • 516
  • 4
  • 15

0 Answers0