SupportMapFragment set google maps Zoom level - android

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));

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);

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));

Android studio location

Iv made a location app, when I open it it opens on a map of the world and I have to hit the target icon thing in the top right hand corner for it to zoom into user location, how do I make it automatically zoom to user location when app is opened?
LocationManager locationManager = (LocationManager) getActivity()
.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
Location location = locationManager
.getLastKnownLocation(locationManager.getBestProvider(criteria,
false));
if (location != null) {
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(d.getLatitude(), d.getLongitude()), 13));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets
// the
// center
// of
// the
// map
// to
// location
// user
.zoom(14) // Sets the zoom
.bearing(0) // Sets the orientation of the camera to east
.tilt(40) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
// change marker you
}
You can use CameraPosition to show users location.
CameraPosition cameraPosition = new CameraPosition.Builder ()
.target (curentpoint).zoom (10f).tilt (70).build ();
Where target is current LatLog getting from either gps or network.
zoom will Zoom map to 10. tilt will change map's angle.
after that use animateCamera method to add cameraposition.
mGoogleMap.animateCamera (CameraUpdateFactory
.newCameraPosition (cameraPosition));
I hope this is what you want.

My App not loading Google map

I am using this code for load google map
private GoogleMap myMap;
if(myMap!=null){
myMap.setMyLocationEnabled(true);
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
marker = myMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title(getAddress(latitude, longitude)));
Location = new LatLng(latitude, longitude);
CameraPosition cameraPosition = new CameraPosition.Builder().target(Location).zoom(15)
.bearing(90) // Sets the orientation of the camera to
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
// myMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 15));
}
but map is not loading and occurring this issue
You must install the latest Google play services in your phone/tab/emulator before running the app.
For google play on emulator.

android google maps moving the camera to different locations with animation

Hi I am trying to change the camera in different locations with an animation. What happens is that when the map opens it zooms to a location then it stops for 6 secs and then it moves to another location with a camera animation. My question is that when this is finished how can I create a 3rd location and then move the camera from the 2nd location to the 3rd? Any idea guys ? Thanks. Here is my code.
public class THEMAP extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleMap map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
LatLng loc1 = new LatLng(41.889, -87.622);
LatLng loc2 = new LatLng(45.889, -87.622);
LatLng loc3 = new LatLng(49.889, -87.622);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(loc1, 10));
map.animateCamera(CameraUpdateFactory.zoomIn());
map.animateCamera(CameraUpdateFactory.zoomTo(10), 6000, null);
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.green))
.position(loc2)
.flat(true)
.rotation(245));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.green))
.position(loc1)
.flat(true)
.rotation(245));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.green))
.position(loc3)
.flat(true)
.rotation(245));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(mapCenter2)
.zoom(8)
.bearing(90)
.tilt(30)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition ),
8000, null);
}
}
The problem is that if i add another location+marker and try to do the above code, the map animates only the 3rd location ignoring the animation of the 2nd location. Any advice guys ?Please help.
CameraPosition cameraPosition2 = new CameraPosition.Builder()
.target(loc3)
.zoom(8)
.bearing(90)
.tilt(30)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition2 ),
8000, null);
Here's your answer: http://ddewaele.github.io/GoogleMapsV2WithActionBarSherlock/part3
It seems you need to implement the second animation in the onFinish() callback of the second animation.

Categories

Resources