0

i have written the code to have google maps in one of my fragments(tabs) and i seem to be having a problem with the on map read call back, its saying its unused import statement. all my libraries have been compiled, i have synced the gradle and it still wont work, i'm still new to android so this isn't my strongest area.

here is my code below

package com.example.hp_user.shoutfinal28;



import android.os.Bundle;

import android.support.v4.app.Fragment;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;


import com.google.android.gms.maps.MapFragment;

import com.google.android.gms.maps.GoogleMap;

import com.google.android.gms.maps.OnMapReadyCallback;



public class FragmentShouts_Maps extends Fragment implements onMapReadyCallback { View view = inflater.inflate(R.layout.fragmentshouts_maps, container, false);
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Get the view from fragment shouts.xml
   return  inflater.inflate(R.layout.fragmentshouts_maps, container, false);

    MapFragment fragment = (MapFragment)getChildFragmentManager().findFragmentById(R.id.maps);
    fragment.getMapAsync(this);
}


@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);




}

@Override
public void onMapReady (GoogleMap googleMap)




}

here is the xml file where i declare maps

<RelativeLayout 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" >

<fragment android:id="@+id/maps"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.example.hp_user.shoutfinal28.FragmentShouts_Maps"
    android:layout_alignParentEnd="true">
</fragment>

</RelativeLayout>

1 Answers1

0

On the line

public class FragmentShouts_Maps extends Fragment implements onMapReadyCallback { 

the first letter of onMapReadyCallback should be capitalised: OnMapReadyCallback

PS: Not related to the error you mentioned, but you also have to carry the line

View view = inflater.inflate(R.layout.fragmentshouts_maps, container, false);

to the inside of the onCreateView method.

ozo
  • 763
  • 7
  • 13
  • thank you, its working, i also moved it into the onCreateView and returned view instead. @ozlem – Alexander Rufus Mar 23 '16 at 10:07
  • now i have a problem with the mapfragment the whole line says incovertible type **_MapFragment fragment = (MapFragment)getChildFragmentManager().findFragmentById(R.id.maps);_** @Ozlem – Alexander Rufus Mar 23 '16 at 10:08
  • Can you post the xml file where you defined R.id.maps? – ozo Mar 23 '16 at 10:24
  • Because "R.id.maps" is a Fragment, but you try to assign it to MapFragment. I don't know what exactly you want to do but you may try FragmentTransaction like in http://stackoverflow.com/questions/15433820/mapfragment-in-fragment-alternatives. – ozo Mar 23 '16 at 10:50
  • I found the answer I was Returning the view before the end of the function so mapfragment's lines of code was being skipped – Alexander Rufus Mar 23 '16 at 11:51