问题
Hi I'm trying to implement Google Maps display in my app using Google Map Android API v2, and I am trying to follow the solution in here.
Codes seem to be okay except when I tried this part:
public class MapFragment extends SherlockMapFragment {
private GoogleMap mMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = super.onCreateView(inflater, container, savedInstanceState);
mMap = getMap();
return root;
}
}
The getMap() gives an error, as it says method getMap() is undefined for the type MapFragment. What does this mean?
回答1:
The getMap()
method is part of the com.google.android.gms.maps.SupportMapFragment
class. Your SherlockMapFragment
should be extending this in the first place so just using getMap()
shoudl work properly but unless you're doing some actual extra customizations with the ActionBar in the MapFragment and not your FragmentActivity, you can just extend SupportMapFragment
in the first place.
来源:https://stackoverflow.com/questions/14537196/google-map-android-api-v2-getmap-error