Hi All, I could really use some help. I'm struggling through tutorials to make a new Android Google Maps v2 plugin that's compatible with Vuforia (I am already Using GlobeKit for iOS and I need it to be similar in function). I've only been working in Android for a few weeks and have had a lot of success but this part has me stumped. Unity 4.2 Vuforia 2.6.7, Target 4.1.2. I'm relatively certain my manifest is setup correctly.
I have tried the following. In mymap.xml
<?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment"/>
package ca.futurestories.landslideMapTest; import java.util.Timer; import java.util.TimerTask; import android.app.FragmentManager; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; //import android.support.v4.app.FragmentManager; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout.LayoutParams; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; import com.qualcomm.QCARUnityPlayer.QCARPlayerActivity; import com.qualcomm.QCARUnityPlayer.QCARUnityPlayer; import com.qualcomm.QCAR.*; public class QCARJavaActivity extends QCARPlayerActivity { private QCARUnityPlayer mQCARView = null; private Timer mViewFinderTimer = null; public SupportMapFragment mMapFragment; private GoogleMap googleMap; private int mapType = GoogleMap.MAP_TYPE_HYBRID; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public void onResume() { super.onResume(); if (mQCARView == null) { //search the QCAR view mViewFinderTimer = new Timer(); mViewFinderTimer.scheduleAtFixedRate(new QCARViewFinderTask(), 1000, 1000); } } @Override public void onPause() { super.onPause(); if (mViewFinderTimer != null) { mViewFinderTimer.cancel(); mViewFinderTimer = null; } } class QCARViewFinderTask extends TimerTask { public void run() { QCARJavaActivity.this.runOnUiThread(new Runnable() { public void run() { if (!QCAR.isInitialized()) return; //wait for QCAR init if (mQCARView != null) return;//already found, no need to search //else search View rootView = QCARJavaActivity.this.findViewById(android.R.id.content); QCARUnityPlayer qcarView = findQCARView(rootView); //if QCAR view has been found, add some android view/widget on top if (qcarView != null) { ViewGroup qcarParentView = (ViewGroup)(qcarView.getParent()); View myView = getLayoutInflater().inflate(R.layout.mymap, null); qcarParentView.addView(myView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); mQCARView = qcarView; } } }); } private QCARUnityPlayer findQCARView(View view) { if (view instanceof QCARUnityPlayer) { return (QCARUnityPlayer)view; } if (view instanceof ViewGroup) { ViewGroup vg = (ViewGroup)view; for (int i = 0; i < vg.getChildCount(); ++i) { QCARUnityPlayer foundView = findQCARView(vg.getChildAt(i)); if (foundView != null) return foundView; } } return null; } } }
But this just gives me the runtime crash:
//if QCAR view has been found, add some android view/widget on top if (qcarView != null) { ViewGroup qcarParentView = (ViewGroup)(qcarView.getParent()); FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); MapFragment fragment = new MapFragment(); fragmentTransaction.add(<?????????>, fragment); fragmentTransaction.commit();
mQCARView = qcarView;
}
But I can't seem to figure out what goes <?????> here. If i was creating the activity view programmatically I would use R.id.MyMapView, or something of the sort, I'd imagine. But Since I'm getting the ViewGroup of QCAR's parent, I can't figure out what the Fragment Container is supposed to be.
Can someone please help? Either conceptually to tell me what design model to follow, or specifically if you know how this should be accomplished.
I should also mention that all other attempts to create the SupportMapFragment using the XML files work, but aren't compatible with Vuforia. So I'm 99% sure I have my eclipse environment setup correctly, as long as I'm not accessing the fragment then the Vuforia code builds and runs. So really it's just about overlaying a MapFragment in a way that's compatible with Vuforia.
Thanks in advance.
Okay I have a work around but it's not pretty. This looks like the right way to do it but it destroys the map each time... so there's no way to just control the visibility with a map loaded with markers and polygons.
I have to remove the mapFragment every time which wipes all the markers... so I have to re-add them and re-load the map every time. But it seems to work well enough for now and I can even control if the map goes on top of the camera feed.
Thanks for your help! It's always appreciated!