可能与Google Maps v2重复- 设置我的位置并放大
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_g_maps); GoogleMap googleMap; LatLng myPosition; SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); googleMap = fm.getMap(); googleMap.setMyLocationEnabled(true); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); if(location!=null){ double latitude = location.getLatitude(); double longitude = location.getLongitude(); LatLng latLng = new LatLng(latitude, longitude); myPosition = new LatLng(latitude, longitude); } } }
我试过添加:
CameraUpdate center= CameraUpdateFactory.newLatLng(new LatLng(latitude, longitude)); CameraUpdate zoom=CameraUpdateFactory.zoomTo(15); googleMap.moveCamera(center); googleMap.animateCamera(zoom);
要么
googleMap.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude) ,4) );
但是,一旦我点击调用此方法的按钮,Google地图就不会自动放大.我仍然可以点击Google UI,我可以点击它来放大我的位置,但我希望它能自动放大.
有什么帮助吗?
试试这个问题的简单解决方案
LatLng coordinate = new LatLng(lat, lng); CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(coordinate, 5); map.animateCamera(yourLocation);
并且..
可以一次改变位置,变焦,方位和倾斜.也可以在animatecamera调用上设置持续时间.
CameraPosition cameraPosition = new CameraPosition.Builder() .target(MOUNTAIN_VIEW) // Sets the center of the map to Mountain View .zoom(17) // Sets the zoom .bearing(90) // Sets the orientation of the camera to east .tilt(30) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
看看这里的文档:
https://developers.google.com/maps/documentation/android/views?hl=fr-FR#moving_the_camera