0

The problem:

I need to put a MapView in a ViewPager

More informations:

As the Mapview will be static (clickable="false") I won't have any issue with scrolling, or touch events. The ViewPager will get every touch and that's it.

What I have tried:

After a lot of Google search, I have found this awesome lib: https://github.com/inazaruk/map-fragment

My code in the Pager Adapter:

@Override
public Fragment getItem(int position) {
        return new MyMapFragment(itineraries);
}

and my Constructor in the MyMapFragment:

public ArrayList<Itinerary> itineraries;

public MyMapFragment(ArrayList<Itinerary> itineraries) {
    super();
    this.itineraries = itineraries;
}

And that's working, I am really happy happy with the result and the behaviour when clicked is set to false

My Question:

As I want to draw the itineraries, I am completely stuck.

The MapFragment does not have any of the Mapview functions. I know I can edit the MyMapActivity class and make everything work there, but how is that possible to send the ArrayList from the Fragment to the Activity?

Currently the MapACtivity does not have any variable to draw the markers. All these informations are in the MapFragment

Waza_Be
  • 39,407
  • 49
  • 186
  • 260

1 Answers1

0

As I understand you right, use ItemizedOverlay<OverlayItem> (just put image instead to draw the marker on the map).

public class MyViewActivity extends MapActivity {
....
OverlayItem myMarker;
MapView myMapView;
ItemizedOverlay<OverlayItem> mItemizedoverlay;
GeoPoint mCurrentPoint;

....

Drawable drawable = this.getResources().getDrawable(R.drawable.target);
    mItemizedoverlay = new MyItemizedOverlay(drawable, this);

....

Address address = ...;
....
mCurrentPoint = new GeoPoint((int) (address.getLatitude() * 1E6), (int) (address.getLongitude() * 1E6));
myMarker = new OverlayItem(mCurrentPoint, "Submit", toSearch);
            mItemizedoverlay.addOverlay(myMarker);
            myMapView.getOverlays().add(mItemizedoverlay);

....
Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
  • The big problem is that mCurrentPoint to display the Marker is known inside the MapFragment (in my itineraries Array). But I cannot pass it to the MapACtivity. – Waza_Be Nov 16 '12 at 23:01