1

I'm triying to use google map on my Android App and I have some problems,

First my class Geoloc.java :

public class Geoloc extends MapFragment {

private MapView map;
private GoogleMap nmap;
private static final String TAG = "MyActivity";

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.e(TAG, "super1");
    Log.d(TAG, "super2");
    Log.v(TAG, "super3");
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.map, container, false);

    if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity().getApplicationContext()) == ConnectionResult.SUCCESS) {

        map = (MapView) view.findViewById(R.id.mapView);
        map.onCreate(savedInstanceState);

        nmap = map.getMap();
        nmap.getUiSettings().setMyLocationButtonEnabled(false);
        nmap.setMyLocationEnabled(true);
        MapsInitializer.initialize(this.getActivity());

        nmap.addMarker(new MarkerOptions().position(new LatLng(10, 10)).title("Hello world"));
        nmap.addMarker(new MarkerOptions().title("title").snippet("description").position(new LatLng(49.5594950, -1.8414880))).showInfoWindow();

    } else {
        Toast.makeText(getActivity(), "Please install google play services", Toast.LENGTH_LONG).show();
    }
    return view;
}

Then my Accueil.java :

map.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            cancelAsyncTask();
            fg = com.lan.me.Geoloc.newInstance();
            //Geoloc = new Geoloc();
            getFragmentManager().beginTransaction().replace(R.id.fg_accueil, fg).commit();
            currentFg = CurrentFragment.MAP;
        }
    });

And finally my map.xml :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <com.google.android.gms.maps.SupportMapFragment
            android:id="@+id/mapView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
</RelativeLayout>

I just check with some log.d-e and finally I just understand that my class Geoloc is never used, but I don't really get why ....?

Does someone know how to fix this problem ? (I have a map but i can do nothing on it because it's only the xml who is created it)

kritzikratzi
  • 19,662
  • 1
  • 29
  • 40
Nicolas Le Bot
  • 324
  • 5
  • 15
  • 2
    You are using `SupportMapFragment` in xml & extending `MapFragment` – VenomVendor Jul 30 '14 at 17:53
  • I do not see where you actually instantiate and use your Geoloc object. Where are you doing that? I see fg = com.lan.me.Geoloc.newInstance(); Not sure if it should be fg = new Geolog(); followed by fg.yourGeolocMethod(); – Mr. Concolato Jul 30 '14 at 17:54
  • Also the GoogleMap object isn't fully loaded until onActivityCreate(), but you say you get a Map. I would have expected you to crash with a NullPointerException. But VenomVendor is right, you need to match up your Fragment classes. – RoraΖ Jul 30 '14 at 17:59
  • Changing something right now in my xml doesn't change anything. But for @Mr.Concolato I think he is right, I just put fg = new Geoloc(), but for after I can't call any functions (because of my arguments) or i don't get how to do. – Nicolas Le Bot Jul 30 '14 at 18:04
  • I change SUpportMapFragment by MapFragment in the XML and change nothing. And for the onActivityCreate, I don't have this function. – Nicolas Le Bot Jul 30 '14 at 18:24

1 Answers1

0

I just find how to do it, and in my geoloc.java i change a lot of things finally :

public Geoloc() {
    super();
}

public static Geoloc newInstance() {
    Geoloc fragment = new Geoloc();
    return fragment;
}

@Override
public View onCreateView(LayoutInflater arg0, ViewGroup arg1, Bundle arg2) {
    View v = super.onCreateView(arg0, arg1, arg2);
    initMap();
    return v;
}

Like this, it works fine ! Thank for help guys. Subject can be closed if you wish.

Nicolas Le Bot
  • 324
  • 5
  • 15