2015-09-11 92 views
0

当我打开应用程序时,它显示整个世界,我必须不断放大才能正确查看该位置。如何使相机缩放约11倍,就好像我要保持双击一样?如何放大Google地图位置?

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 

    } 

    @Override 
    public void onMapReady(GoogleMap map) { 
     map.addMarker(new MarkerOptions() 
       .position(new LatLng(10.625176, -61.354915)) 
       .title("Tru-Valu, Trincity Mall")); 
    } 

回答

0

试试这个:

LatLng coordinate = new LatLng(lat, lng); 
CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(coordinate, 5); 
map.animateCamera(yourLocation); 
0

到米拉德·努里的答案类似,最初的用户可能没有位置上,而FusedLocationProvider不会有最后的位置,但因为API客户,不是招”开始。所以,我的技巧是将用户的上一次经纬度保存到savedPreferences,并在应用程序启动时将此位置作为初始相机动画的LatLng加载。

我在最后更新时保存LatLng,因此它只记得在地图上为用户位置更新的最后一次经纬度。

1

GoogleMap具有定位和缩放的“移动”和“动画”方法。

您可以通过CameraUpdateFactory获取CameraUpdate对象。这里有些例子。

  • CameraUpdateFactory.newLatLng(LatLng latLng)

返回移动屏幕的一个 纬度和经度由经纬度对象指定的中心提供CameraUpdate。这将 相机放在LatLng对象上。

  • CameraUpdateFactory.newLatLngZoom(LatLng latLng, float zoom)

返回移动屏幕的一个 纬度和经度由经纬度对象指定的中心提供CameraUpdate,并移动到给定的 缩放级别。

  • CameraUpdateFactory.zoomBy(float amount)

返回移动当前 摄像机视点的缩放级别的CameraUpdate。

您可以在CameraUpdateFactory documenation中找到其他辅助方法。另外,关于移动谷歌地图的相机,这里非常有用documentation from Google Developers

所以,如果你想在Tru-Valu, Trincity Mall地方放大,这是你的代码应该怎么看起来像

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
     new LatLng(10.625176, -61.354915), 16f)); 
相关问题