Is it possible to change the zoom level for myLocation with the new Google Maps API v2?
If you set GoogleMap.setEnableMyLocation(true);, you get a button on the map to find your location.
If you click on it, then the map will bring you to your location and zoom it in to some level. Can I change this zoom to be less or more?
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));
}
}
You can also use:
mMap.animateCamera( CameraUpdateFactory.zoomTo( 17.0f ) );
To just change the zoom value to any desired value between minimum value=2.0 and maximum value=21.0.
The API warns that not all locations have tiles at values at or near maximum zoom.
See this for more information about zoom methods available in the CameraUpdateFactory.
with location - in new GoogleMaps SDK:
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(chLocation,14));
Here are the approximate zoom levels and what they do :
1: World
5: Landmass/continent
10: City
15: Streets
20: Buildings
so you could do something like this to zoom to street level for example (note the "15f" below is street level) :
override fun onMapReady(googleMap: GoogleMap?) {
googleMap?.mapType = GoogleMap.MAP_TYPE_NORMAL
googleMap?.addMarker(MarkerOptions()
.position(LatLng(37.4233438, -122.0728817))
.title("cool place")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE)))
googleMap?.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(37.4233438, -122.0728817), 15f))
note: just so you know different locations can have different max zoom levels. try to use googleMap.maxZoomLevel if you want to get the max or min zoom levels.
Slightly different solution than HeatfanJohn's, where I change the zoom relatively to the current zoom level:
// Zoom out just a little
map.animateCamera(CameraUpdateFactory.zoomTo(map.getCameraPosition().zoom - 0.5f));
In onMapReady() Method
change the zoomLevel to any desired value.
float zoomLevel = (float) 18.0;
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoomLevel));
you have to write only one line in maps_activity.xml
map:cameraZoom="13"
I hope this will solve your problem...
You can use
CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude()));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(12);
Even i recently had the same query....some how none of the above mentioned setmaxzoom or else map:cameraZoom="13" did not work
So i found that the depenedency which i used was old
please make sure your dependency for google maps is correct
this is the newest use this
compile 'com.google.android.gms:play-services:11.8.0'
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentPlace,15));
This is will not have animation effect.
I tried with "mMap.animateCamera( CameraUpdateFactory.zoomTo( 17.0f ) );" but it didn't work for me. So I used this animation for zooming in on start.
LatLng loc = new LatLng(33.8688, 151.2093);
mMap.addMarker(new MarkerOptions().position(loc).title("Sydney"));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(loc, 18), 5000, null);
Location locaton;
double latitude = location.getlatitude;
double longitude = location.getlongitude;
If you want to save the zoom or get it all the time,you just need to call the following
int zoom = mMap.getCameraPosition().zoom;
//To set that just use
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(getlatitude(), getlongitude),zoom);
Most of the answers above are either deprecated or the zoom works by retaining the current latitude and longitude and does not zoom to the exact location you want it to. Add the following code to your onMapReady() method.
#Override
public void onMapReady(GoogleMap googleMap) {
//Set marker on the map
googleMap.addMarker(new MarkerOptions().position(new LatLng(0.0000, 0.0000)).title("Marker"));
//Create a CameraUpdate variable to store the intended location and zoom of the camera
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(0.0000, 0.0000), 13);
//Animate the zoom using the animateCamera() method
googleMap.animateCamera(cameraUpdate);
}
Related
I have a GoogleMap (Lite Mode) object that has been properly initialized. It works properly with a single Marker and focuses on the proper area using CameraUpdate with newLatLngZoom.
However, when it comes to adding two markers, and have the map keep both in view using LatLngBounds, everything goes bonkers. The map is so zoomed out it shows the entire continent, and the two markers are on-top of each other (along with the polyline).
Kindly assume that the data from the pickup and destination is correct
Here's my code:
googleMap.addMarker(new MarkerOptions()
.position(pickup)
.title(job.getPickupAddress()));
googleMap.addMarker(new MarkerOptions()
.position(destination)
.title(job.getDestinationAddress())
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(new LatLngBounds.Builder().include(pickup).include(destination).build(), 0);
googleMap.moveCamera(cameraUpdate);
String pickupLatLng = job.getPickupLatLong().latitude + "," + job.getPickupLatLong().longitude;
String destinationLatLng = job.getDestinationLatLong().latitude + "," + job.getDestinationLatLong().longitude;
plotPolyLines(pickupLatLng, destinationLatLng);
Output:
Setting a zoom with latlng bounds is not an effective solution for all use cases.
Might be a related Bug Maps Lite mode with incorrect zoom level first time app starts
Try few solutions / hacks listed here : https://issuetracker.google.com/issues/36218443
Like refreshing the map by destroying and recreating
Also check if by using a single marker with bounds builder if the map sets to the proper zoom level
One last thing make sure that zoom level limits have not been applied.
try changing the line
googleMap.moveCamera(cameraUpdate);
to
googleMap.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(xxxx,xxxx) , 14.0f) );
as suggested in How do I set default location and Zoom level for google map api v2?
or use
map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
That should move the camera closer to your marker.
I have implemented google map into my app. I have added a custom marker at my current location.I want to move the marker as the user moves, along with the map. I want to implement the functionality as in google maps navigation. While googling i found the following links but did not get the result. so can any one help me out ?
I have added this in onLocationChanged()
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
sourceLocation = latLng;
startPoint = new GeoPoint(latLng.latitude,latLng.longitude);
forNavigation = location;
// animation
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
// Zoom in the Google Map
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
// mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mPositionMarker.getPosition(), 15));
mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location
.getLatitude(), location.getLongitude())));
These are the links which i found
Google map: moving marker and map together smoothly along with user?
How to smoothly keep moving current location marker in Google Maps v2 android
here is two solution you have.
Use onlocationtrue then it show you blue dot as your current location.
Use fused api for current location and create you marker in locationchanged.
for fused api you can check from here.
thanks
I am writing an app that uses Google Maps Android API V2. The app will center on a specific latitude and longitude (this position is hard coded to 36.5323, -87.3546) when the user turns on the map and get the user's position every 15 seconds. However, when the user first turns the camera on it centers to (8.407168163601076,-87.35459994524717).
This only happens when the user first turns the map on. If the map is turned off and then turned back on, it centers on the correct coordinates. This has only happened on a Nexus 9. I have two other devices for testing where it properly centers the map on the first try.
This is the code I call to center the map:
LatLng pos = new LatLng(36.5323, -87.3546);
CameraUpdate center = CameraUpdateFactory.newLatLng(pos);
CameraUpdate zoom = CameraUpdateFactory.zoomTo(14);
map.moveCamera(center);
map.animateCamera(zoom);
Can anyone tell me why this is happening?
try this
LatLng pos= new LatLng(LATITUDE, LONGITUDE);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 16);
map.animateCamera(cameraUpdate);
I would like to force the camera to behave like you are using navigation, it means when you rotate 90° left, the camera does the same thing.
I have a Google Map where my location (as a blue dot) is shown.
mGoogleMap.setMyLocationEnabled(true);
When I am moving, blue dot is with an arrow which shows my current bearing. I would like to get this bearing.
I am getting my current location using FusedLocationApi:
currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
Code below is animating camera to current location, but without the bearing. I can add the bearing, but I don't know the value.
#Override
public void onLocationChanged(Location location) {
LatLng latLng = new LatLng( location.getLatitude(), location.getLongitude() );
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
}
Do you know how to get the current location direction? I was unable to find any proper information about that. I would greatly appreciate any help you can give me.
Thank you
I think you can try to use getOrientation(R, orientation) (and adjust for true north) to get the device rotation. You can refer to here.
Also, use the CameraPosition class here to adjust camera position.
EDIT: I even found better solution. Use getBearing() method in Location class.
if (location.hasBearing()) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng) // Sets the center of the map to current location
.zoom(15) // Sets the zoom
.bearing(location.getBearing()) // Sets the orientation of the camera to east
.tilt(0) // Sets the tilt of the camera to 0 degrees
.build(); // Creates a CameraPosition from the builder
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
I have been able to open up a map of the world through code and mark a few places. However, I always have to zoom down to the city, which takes a little while. Is there any way to directly open up a map of a particular city?
You can use moveCamera with your last stored location (lat, lng and maybe zoomLevel too) for example.
final LatLng location = new LatLng(..., ...);// Loaded from SharedPreferences maybe.
// Move the camera to location with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 15));
You can use this sample code to animate the map directly to your city coordinate (lat, lng) and automatically zooming out to specified level :
// Set desired lat lng location, and zoom level (for example 10)
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(locationCity.getLatitude(), locationCity.getLongitude()), 10);
// Move the camera to location
gMap.animateCamera(cameraUpdate);