Set Location Center of Map - GMaps v2 - Android

谁说胖子不能爱 提交于 2019-12-30 08:12:31

问题


How do I set the center of the map to a specific location using GMaps v2? This is how I did it using GMaps v1:

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;
     }*/
  }
}

I have looked through the API for GMaps v2 and can't find and similar functionality. How do I do this?


回答1:


You can try:

map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), zoom));

where map is the GoogleMap instance.




回答2:


@Override
public void onMapReady(GoogleMap googleMap) {
    final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);
    googleMap.addMarker(new MarkerOptions().position(SYDNEY));
    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 4.0f));
}


来源:https://stackoverflow.com/questions/16342234/set-location-center-of-map-gmaps-v2-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!