Google Maps v2 - set both my location and zoom in
You cannot animate two things (like zoom in and go to my location) in one google map?
From a coding standpoint, you would do them sequentially:
CameraUpdate center=
CameraUpdateFactory.newLatLng(new LatLng(40.76793169992044,
-73.98180484771729));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);
map.moveCamera(center);
map.animateCamera(zoom);
Here, I move the camera first, then animate the camera, though both could be animateCamera()
calls. Whether GoogleMap
consolidates these into a single event, I can't say, as it goes by too fast. :-)
Here is the sample project from which I pulled the above code.
Sorry, this answer is flawed. See Rob's answer for a way to truly do this in one shot, by creating a CameraPosition
and then creating a CameraUpdate
from that CameraPosition
.
Android Google Maps v2 - set zoom level for myLocation
It's doubtful you can change it on click with the default myLocation Marker. However, if you would like the app to automatically zoom in on your location once it is found, I would check out my answer to this question
Note that the answer I provided does not zoom in, but if you modify the onLocationChanged method to be like the one below, you can choose whatever zoom level you like:
@Override
public void onLocationChanged(Location location) {
if( mListener != null ) {
mListener.onLocationChanged( location );
//Move the camera to the user's location and zoom in!
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 12.0f));
}
}
How do I set default location and Zoom level for google map api v2?
you can use this to zoom directly without the animation :
map.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(xxxx,xxxx) , 14.0f) );
Adjusting google map (api v2) zoom level in android
In my project I use the com.google.android.gms.maps.model.LatLngBounds.Builder
Adapted to your source code it should look something like this:
Builder boundsBuilder = new LatLngBounds.Builder();
boundsBuilder.include(currentLocationLatLng);
boundsBuilder.include(targetLocationLatLng);
// pan to see all markers on map:
LatLngBounds bounds = boundsBuilder.build();
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 3));
Fix zoom level between two Marker in Google-Map
You are using the correct code, and the value (50) needs to be increased if you want to zoom less (be outer) or decreased to 0 if you want to be in the smallest area containing the two markers (you can skip the value in case).
If you set a value of 150 or more, and the level is too much you can use the animation callback to zoom out after the LatLng
zoom:
Google API
com.google.android.gms.maps.GoogleMap.CancelableCallback)
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(origin);
builder.include(dest);
LatLngBounds bounds = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 50);
mMap.animateCamera(cu, new GoogleMap.CancelableCallback(){
void onCancel(){}
void onFinish(){
CameraUpdate zout = CameraUpdateFactory.zoomBy(-3.0);
mMap.animateCamera(zout);
}
});
This should zoom to the LatLng
and when finished, zoom back of 3 levels.
changing the position of google maps SupportMapFragment Zoom and My location controls not work
You can find Location button on map by getting parent view first and then "My Location" button as below :
// Get the "My Location" button view
View locationButton = ((View) mapView.findViewById(1).getParent()).findViewById(2);
// get button params to place the button
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
// place on right bottom corner
rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
rlp.setMargins(0, 0, 30, 30);
If want to resize button, you can get parameters like below :
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(100, 100);
//.... do your editing
// To set params to button
locationButton.setLayoutParams(lp);
Related Topics
Android- Phonegap/Webview Ignores Viewport Meta Tags
Android - Activity Not Found Exception
How to Close Activity and Go Back to Previous Activity in Android
How to Style Appcompat-V7 Toolbar Like Theme.Appcompat.Light.Darkactionbar
How to Encode Bitmaps into a Video Using Mediacodec
How to Create a Release Android Library Package (Aar) in Android Studio (Not Debug)
Right Align Text in Android Textview
Best Way to Show a Loading/Progress Indicator
How to Make a Dialog Slide from Bottom to Middle of Screen in Android
Pcm -> Aac (Encoder) -> Pcm(Decoder) in Real-Time with Correct Optimization
Overriding the Power Button in Android
How to Secure My App Against Piracy
What's "Requestcode" Used for on Pendingintent
What Are The Default Color Values for The Holo Theme on Android 4.0
How to Handle App Lifecycle with Flutter (On Android and iOS)