-2

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.

user268397
  • 1,917
  • 7
  • 38
  • 56
  • 1
    What *specific* "MapController functionality" are causing you problems? The documentation explains how to set the center and zoom: https://developers.google.com/maps/documentation/android/views – CommonsWare May 02 '13 at 14:31
  • It's not part of the Google Play Services library for GMaps v2. So I'm trying to convert the MapController functionality so that it is v2 compatible. I'm not sure how to go about doing this. Everything that is wrong with my code has to do with the MapController class. – user268397 May 02 '13 at 14:35
  • When you clicked on the hyperlink in my preceding comment, and read that Web page, what did you learn? – CommonsWare May 02 '13 at 14:39
  • All that functionality is already built in to v2... – tyczj May 02 '13 at 15:24
  • Where is the functionality though to set the center of the map using a specific Geopoint? I could not find anything in the documentation that did that like setCenter() does in Gmaps v1.1. – user268397 May 02 '13 at 15:30
  • did you even click on the link that CommonsWare posted because it says exactly how to do that – tyczj May 02 '13 at 15:41
  • Yes I did. I have looked through all of that and there is nothing in there or in the API documentation with that functionality. – user268397 May 02 '13 at 15:43
  • The easiest way to switch from v1 to v2 is to remove all the code and start from scratch. These APIs are not compatible in any way. – MaciejGórski May 03 '13 at 09:13

1 Answers1

1

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));
tyczj
  • 71,600
  • 54
  • 194
  • 296