2

I'm using the Android Compatibility Package and I've tried to add the MapView in the Fragment's onCreateView. However the map doesn't zoom or show the right coordinates. It only shows the whole world map (lowest detail).

Here is the simple code that should normally work

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    MapView mapView = new MapView(getActivity(), 256);
    mapView.getController().setZoom(14);
    mapView.getController().setCenter(new GeoPoint(46814000,17977000));
    return mapView;
}

Hope somebody knows how to solve this.

Thanks

Warpzit
  • 27,966
  • 19
  • 103
  • 155
Filip Kis
  • 1,650
  • 2
  • 14
  • 18
  • OK, I managed to figure out what was wrong. The reason why the zoom and coordinates were not set is because this was another map (that was loaded from XML) and that one was showing as default. The one I initiated above was not shown at all. And the reason why is because you have to add it to RelativeLayout first. And then the relative layout should be the one that's returned. – Filip Kis Sep 02 '11 at 14:14
  • Hmm... you can add a MapView in MapActivity only, and there is no MapActivity in compatibility package? You suppose to get java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity. ? –  Sep 15 '11 at 18:50

1 Answers1

1

to @Tony you probably have figured this out already but the MapFragment only exists in the compatibility packages. The common solution at this time is to use MapActivity as the activity and add fragments there or to use the compatibility package and add the Fragment in by way of a TabHost and a LocalActivityManager http://stackoverflow.com/questions/5109336/mapview-in-a-fragment-honeycomb

Sean
  • 196
  • 11