我正在尝试将此代码的旧版本从 GMaps v1.1 转换为 GMaps v2。我在转换以下 MapController 代码时遇到问题:
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;
}
这是我要转换的整个文件:
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;
}
}
}
在转换到 v2 时,我可以使用什么代码来替换此 MapController 功能?任何的意见都将会有帮助。