Reputation: 13302
I am using Google map, to add multiple marker to it.
But when the map loads, it does not focus on the markers on the map.
public class MapActivity extends AppCompatActivity implements OnMapReadyCallback {
....
private void loadMap(){
Log.d(TAG, "loadMap");
//Load MAP
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
public void onMapReady(GoogleMap map) {
map.addMarker(new MarkerOptions().position(new LatLng(doubleLat, doubleLon)).title(name));
}
Upvotes: 1
Views: 5460
Reputation: 47817
Animate Camera
on that Marker
LatLng pos=new LatLng(latitude,longitude);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(pos, 18.0f));
Upvotes: 4
Reputation: 3243
You have to use CameraUpdateFactory
to achieve the same, you can do like below :
CameraUpdate center=
CameraUpdateFactory.newLatLng(new LatLng(doubleLat, doubleLon));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);
map.moveCamera(center);
map.animateCamera(zoom);
You can add this code inside onMapReady()
callback .
Upvotes: 4