-2

I am working with fragments and Google map... In order to code for the google map functionalities I need to extend mapactivity, however I am unable to do that as I have already extended fragment. Could someone please tell me a fix to this. I would really appreciate.

public class mapFragment extends Fragment

I need to get user's current location through something like this

rivate GoogleMap.OnMyLocationChangeListener myLocationChangeListener = new GoogleMap.OnMyLocationChangeListener() {
    @Override
    public void onMyLocationChange(Location location) {
        LatLng loc = new LatLng(location.getLatitude(), location.getLongitude());
        mMarker = mMap.addMarker(new MarkerOptions().position(loc));
        if(mMap != null){
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(loc, 16.0f));
        }
    }
};

but for this I need to extend map activity.

Thanks.

Android
  • 171
  • 1
  • 4
  • 16
  • Java doesn't allow multiple inheritance. take a look http://stackoverflow.com/a/9921455 http://stackoverflow.com/a/8373685 – Ishtiaq Nov 28 '14 at 05:44

1 Answers1

1

Why dont you use a MapView inside a fragment and do all the necessary google map functionalities with it . Something like

<com.google.android.gms.maps.MapView
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:id="@+id/map" />

Put this inside your xml file. Then do the necessary things with it inside the fragment .