Issue Converting Over To GMaps v2 for Android

I'm trying to convert an old version of this code from GMaps v1.1 to GMaps v2. I am having issues converting the following MapController code:

private MapController mMapController;

public void setController(Object controller)
{
  /*if( controller instanceof org.osmdroid.views.MapView )
  {
     mOpenStreetMapViewControllerSource = (org.osmdroid.views.MapView) controller;
     mMapController = null;
  } else */if( controller instanceof MapController )
  {
     mMapController = (MapController) controller;
     mOpenStreetMapViewControllerSource = null;
  }
}

public void setZoom( int i )
{
  if( mMapController != null )
  {
     mMapController.setZoom( i );
  }
  /*else if( mOpenStreetMapViewControllerSource != null )
  {
     mOpenStreetMapViewControllerSource.getController().setZoom( i );
     mPostponedSetZoom = i;
  }*/
  else 
  {
     throw new IllegalStateException( "No working controller available" );
  }
}

public void animateTo( LatLng point )
{
  if( point.latitude*1000000 != 0 && point.longitude*1000000 != 0 )
  {
     if( mMapController != null )
     {
        mMapController.animateTo( point );
     }
     /*else if( mOpenStreetMapViewControllerSource != null )
     {
        mOpenStreetMapViewControllerSource.getController().animateTo( new org.osmdroid.util.GeoPoint( point.getLatitudeE6(), point.getLongitudeE6() ) );
        mPostponedSetCenterPoint = point;
     }*/
     else 
     {
        throw new IllegalStateException( "No working controller available" );
     }
  }
}

public void setCenter( LatLng point )
{
  if( point.latitude*1000000 != 0 && point.longitude*1000000 != 0 )
  {
     if( mMapController != null )
     {
        mMapController.setCenter( point );
     }
     /*else if( mOpenStreetMapViewControllerSource != null )
     {
        mOpenStreetMapViewControllerSource.getController().setCenter( new org.osmdroid.util.GeoPoint( point.getLatitudeE6(), point.getLongitudeE6() ) );
        mPostponedSetCenterPoint = point;
     }*/
  }
}


public boolean zoomIn()
{
  if( mMapController != null )
  {
     return mMapController.zoomIn();  //USE CameraUpdateFactory for zoomIn() - https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/CameraUpdateFactory
  }
  /*if( mOpenStreetMapViewControllerSource != null )
  {
     return mOpenStreetMapViewControllerSource.getController().zoomIn();
  }*/
  return false;
}

public boolean zoomOut()
{
  if( mMapController != null )
  {
     return mMapController.zoomOut();  //USE CameraUpdateFactory for zoomOut() - https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/CameraUpdateFactory
  }
  /*else if( mOpenStreetMapViewControllerSource != null )
  {
     return mOpenStreetMapViewControllerSource.getController().zoomOut();
  }*/
  return false;
}

Here is the whole file I'm trying to convert:

import android.util.Log;

import com.google.android.gms.maps.model.LatLng;
//import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;

public class MapControllerProxy
{

private static final String TAG = "OGT.MapControllerProxy";
private MapController mMapController;
private org.osmdroid.views.MapView mOpenStreetMapViewControllerSource;
private LatLng mPostponedSetCenterPoint = null;
private int mPostponedSetZoom = -1;

public MapControllerProxy()
{
}


public void setController(Object controller)
{
  /*if( controller instanceof org.osmdroid.views.MapView )
  {
     mOpenStreetMapViewControllerSource = (org.osmdroid.views.MapView) controller;
     mMapController = null;
  } else */if( controller instanceof MapController )
  {
     mMapController = (MapController) controller;
     mOpenStreetMapViewControllerSource = null;
  }
}

public void setZoom( int i )
{
  if( mMapController != null )
  {
     mMapController.setZoom( i );
  }
  /*else if( mOpenStreetMapViewControllerSource != null )
  {
     mOpenStreetMapViewControllerSource.getController().setZoom( i );
     mPostponedSetZoom = i;
  }*/
  else 
  {
     throw new IllegalStateException( "No working controller available" );
  }
}

public void animateTo( LatLng point )
{
  if( point.latitude*1000000 != 0 && point.longitude*1000000 != 0 )
  {
     if( mMapController != null )
     {
        mMapController.animateTo( point );
     }
     /*else if( mOpenStreetMapViewControllerSource != null )
     {
        mOpenStreetMapViewControllerSource.getController().animateTo( new org.osmdroid.util.GeoPoint( point.getLatitudeE6(), point.getLongitudeE6() ) );
        mPostponedSetCenterPoint = point;
     }*/
     else 
     {
        throw new IllegalStateException( "No working controller available" );
     }
  }
}

public void setCenter( LatLng point )
{
  if( point.latitude*1000000 != 0 && point.longitude*1000000 != 0 )
  {
     if( mMapController != null )
     {
        mMapController.setCenter( point );
     }
     /*else if( mOpenStreetMapViewControllerSource != null )
     {
        mOpenStreetMapViewControllerSource.getController().setCenter( new org.osmdroid.util.GeoPoint( point.getLatitudeE6(), point.getLongitudeE6() ) );
        mPostponedSetCenterPoint = point;
     }*/
  }
}


public boolean zoomIn()
{
  if( mMapController != null )
  {
     return mMapController.zoomIn();  //USE CameraUpdateFactory for zoomIn() - https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/CameraUpdateFactory
  }
  /*if( mOpenStreetMapViewControllerSource != null )
  {
     return mOpenStreetMapViewControllerSource.getController().zoomIn();
  }*/
  return false;
}

public boolean zoomOut()
{
  if( mMapController != null )
  {
     return mMapController.zoomOut();  //USE CameraUpdateFactory for zoomOut() - https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/CameraUpdateFactory
  }
  /*else if( mOpenStreetMapViewControllerSource != null )
  {
     return mOpenStreetMapViewControllerSource.getController().zoomOut();
  }*/
  return false;
}

public void executePostponedActions()
{
  if( mPostponedSetCenterPoint != null )
  {
     Log.w( TAG, "mPostponedSetCenterPoint"+ mPostponedSetCenterPoint);
     setCenter( mPostponedSetCenterPoint );
     mPostponedSetCenterPoint = null;
  }
  if( mPostponedSetZoom >= 0 )
  {
     Log.w( TAG, "mPostponedSetZoom"+ mPostponedSetCenterPoint);
     setZoom( mPostponedSetZoom );
     mPostponedSetZoom = -1;
  }
}

}

What code can I use to replace this MapController functionality in my conversion to v2? Any suggestions would be helpful.

Answers


doing this will center the map on a point

CameraPosition position = new CameraPosition.Builder()
            .target(new LatLng(Lat,Lon))
            .zoom(zoom).build();

         map.animateCamera(CameraUpdateFactory.newCameraPosition(position));

Need Your Help

Find delta angle to use for rotation given entity with position, initial rotation and target point to 'face toward'

java math vector rotation ardor3d

I'm coding a flocking algorithm in Java but I'm stuck at a certain point (using the Ardor3D libraries, in a 2D plane).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.