Hello,
I’m trying to set a custom position and view for the camera at startup. However, the camera position is not being updated, even though I’m calling the setPosition() method, right after the loadConfiguration() method.
Here is my code:
public boolean verifyMap(final MapConfigPreferences pConfig) { boolean isMapValid = false; final MapSurfaceView lSurfaceView = new MapSurfaceView(this); // A FutureTask is useful when it's absolutely necessary to get a result from the // GL thread from within the UI thread. // -- Format of expected results -- // lResultStore[0] isMapValid final boolean[] lResultStore = new boolean[1]; FutureTask<boolean[]> lRetrieveResultFromGLThread = new FutureTask<boolean[]>(new Runnable() { @Override public void run() { VgIDatabase lDatabase = lSurfaceView.getApplication().editEngine().editDatabase(); boolean lIsValid = false; if (lDatabase.loadConfiguration(pConfig.mConfigurationFile, pConfig.mSecret, pConfig.mLicenseURL)) { lIsValid = true; } else { VgErrorCode lErrorCode = lSurfaceView.getApplication().editEngine().getLastError(); String lErrorStr = lSurfaceView.getApplication().editEngine().getErrorString(lErrorCode); final String lError = "loadConfiguration failed: " + lErrorStr; MapActivity.this.runOnUiThread(new Runnable() { @Override public void run() { Log.i("MapActivity", lError); } }); } lResultStore[0] = lIsValid; // Create new position VgPosition lPosition = new VgPosition(); lPosition.setMXOrLongitude(1.493148); lPosition.setMYOrLatitude(43.587538); lPosition.setMZOrAltitude(122.239372); VgICamera lCamera = lSurfaceView.getApplication().editEngine().editCamera(); // Set position within camera lCamera.setPosition(lPosition); // Set heading lCamera.setHeading(-171.126800); // Problem! // Camera not being updated. } }, lResultStore); lSurfaceView.queueEvent(lRetrieveResultFromGLThread); boolean[] lResultReturn = new boolean[1]; try { lResultReturn = lRetrieveResultFromGLThread.get(); } catch (Exception e) { e.printStackTrace(); } isMapValid = lResultReturn[0]; return isMapValid; }
Here you’re setting the camera position within the verifyMap() method. This creates a local object MapSurfaceView specifically for performing a loadConfiguration() and validating the map. There is no actual layout being displayed that actually contains this view. This is why you’re not seeing the map being updated.
You should instead call setPosition() on the MapSurfaceView which is created directly from the layout.