Google Map zoom / animation not responding - android

I have a map on one of my activities. The map is working well. However, I'd like to change the zoom and a few animations with the following code. However, none of this is responding. What am I missing? Thanks!
googleMap.addMarker(new MarkerOptions().position(latLng).title(my_location.getLocationName()));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
// Zoom in, animating the camera.
googleMap.animateCamera(CameraUpdateFactory.zoomIn());
// Zoom out to zoom level 10, animating with a duration of 2 seconds.
googleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng) // Sets the center of the map to my coordinates
.zoom(17) // Sets the zoom
.bearing(180) // Sets the orientation of the camera to south
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

Related

GoogleMap : Zoom In And Zoom Out not working android app

I am working on an android game where i have to draw rectangle yard [Football ground]. I draw rectangle on google map using polygon. Code is here:
PolygonOptions polygonOptions = new PolygonOptions()
.add(new LatLng(bounds.northeast.latitude, bounds.northeast.longitude))
.add(new LatLng(bounds.southwest.latitude, bounds.northeast.longitude))
.add(new LatLng(bounds.southwest.latitude, bounds.southwest.longitude))
.add(new LatLng(bounds.northeast.latitude, bounds.southwest.longitude))
.strokeColor(color);
mMap.addPolygon(polygonOptions);
I tried various code for google map zoom in :
Code 1:
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
Code 2 :
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(Latitude, Longitude)) // Sets the center of the map to Mountain View
.zoom(30) // 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));
Code 3 :
map.animateCamera(CameraUpdateFactory.zoomIn());
None of the code works for me. Any help is most welcome!!!
you can add zoom control(buttons) to UI with:
map.getUiSettings().setZoomControlsEnabled(true);

google map animateCamera- > cameraposition target not updating & moveCamera -> cameraposition target updating

I am new to android.i know the difference between google map animateCamera and moveCamera . But I am not sure my doubt is valid or not.Actually in my application, in map centre am having one icon. if we move the map ,app will return the centre location of map.Example :Suppose if I change the centre of the map with some lat long by using move camera like this ,
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(0.0,0.0))
.zoom(14)
.bearing(90)
.build();
map.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
If I get the center of map now is,
Log.e("Location",map.getCameraPosition().target);
Output is : 0.0,0.0
And same operation using animate camera,
CameraPosition cameraPosition = new
CameraPosition animateCameraPosition = new CameraPosition.Builder()
.target(new LatLng(2.0,4.0))
.zoom(14)
.bearing(90)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(animateCameraPosition));
Now the center of map now is,
Log.e("Location",map.getCameraPosition().target);
Output is : 0.0,0.0
I don't know what I am doing wrong ? why animateCamera is not updating the center of the map?

How to place a Marker on center of the screen on google map

Place marker on center of the screen on google map android same as like in uber and ola apps. When moving or scrolling a google map marker should not move and it should give latlng coordinates
You need to put an ImageView center of frameLayout.That is not marker of your map but it place in the center and when you click that imageview you need to get center LatLng of the map
Here is code for getting center LatLng of map :
LatLng center = mgoogleMap.getCameraPosition().target;
You need to use frame layout to align your marker in this case a image like this at center. and then fetch location using googleMap.getCameraPosition().target
for more info see http://developer.android.com/reference/com/google/android/gms/maps/model/CameraPosition.html#target
Try this,
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(currentLatitude, currentLongitude)).zoom(15).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Check Out This
LatLng mapCoordinate = new LatLng(yourLatitude, yourLatitude);
CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(mapCoordinate, 11.0f);
yourMap.animateCamera(yourLocation);
Or In Other way
LatLng mapCoordinate = new LatLng(yourLatitude, yourLatitude);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(mapCoordinate) // set to Center
.zoom(12.0f) // for the Zoom
.bearing(90) // Orientation of the camera to east
.tilt(30) // Tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition
yourMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

SupportMapFragment set google maps Zoom level

how can i set the zoom level of a SupportMapFragment ?
I tried some answers I found in similar questions, like this one answered buy a guy named Rob who proposed:
LatLng currentLocation = mService.getCurrentLocation();
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(currentLocation) // Sets the center of the map to the current location of the user
.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
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
But this solution didn't work. So, how can I set the Zoom level knowing that I use a SupportMapFragment.
if your current location is not null then try this code it will work
LatLng currentLocation = mService.getCurrentLocation();
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(currentLocation , 16);
mMap.addMarker(new MarkerOptions().position(location).title(""));
mMap.moveCamera(CameraUpdateFactory.newLatLng(currentLocation ));
mMap.animateCamera(cameraUpdate)
Marker currentMarker;
MarkerOptions marker = new MarkerOptions().position(new
LatLng(Double.
parseDouble(lat),Double.parseDouble(lon))).title(title);
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_schoolbus));
currentMarker = map.addMarker(marker);
currentMarker.showInfoWindow();
currentMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.ic_schoolbus));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(Double.parseDouble(lat),Double.parseDouble(lon)), 15));

How to apply Camera bounds with CameraPosition in google map

I need to use few features of both CameraPosition and CameraBounds, Like my specific requirement is to move the camera on a bearing and tilt it on a few degrees as well as there are other markers on the map which i want to cover while i perform a camera update .
CameraUpdateFactory class have two different methods on two different purpose.
1) newCameraPosition 2) newLatLngBounds
But i doubt if i can use both of them simultaneously to get the result i want.
CameraPosition works as below :
LatLng current_lat_lng=new LatLng(lat, lon);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(current_lat_lng) // Sets the center of the map to Mountain View
.zoom(googleMap.getCameraPosition().zoom) // Sets the zoom
.bearing((float)mapHeading) // Sets the orientation of the camera to a bearing
.tilt(0) // Sets the tilt of the camera to 0 degrees
.build();
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
CameraBounds work as below :
final LatLngBounds.Builder builder = new LatLngBounds.Builder();
if (marker_Searched != null) {
builder.include(marker_Searched.getPosition());
}
if (marker_selected_taxi != null) {
builder.include(marker_selected_taxi.getPosition());
}
LatLngBounds bounds = builder.build();
int padding = 300; // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
googleMap.moveCamera(cu);
Do anyone have tried any workaround with this ?
Animate your camera to the LatLngBounds with CancellableCallback, then in onFinish get zoom value (map.getCameraPosition().zoom) then apply this value into CameraPosition. It works for me fine.

Categories

Resources