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?
Related
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);
I'm using the Google Maps API and I want to set my camera on a specific marker. When I do this and I start rotating my camera is losing focus on my marker while they both have the same coordinate.
Does someone knows why this is happening?
My code
LatLng myCoordinates = new LatLng(location.getLatitude(), location.getLongitude());
player.setPosition(myCoordinates);
CameraPosition currentPosition = map.getCameraPosition();
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(myCoordinates)
.bearing(currentPosition.bearing)
.zoom(18)
.tilt(currentPosition.tilt)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Click here for a video of the problem. (The orange marker is one that the camera is set on)
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));
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));
I was trying to place a marker in Google Map using the following code.
googleMap.clear();
//Dont know why this is 4.8f...
googleMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.google_marker))
.position(ll).flat(true)
.anchor(0.5f, 0.5f));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(ll)
.zoom(initMapZoom) // Sets the zoom
.build();
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
cameraPosition = new CameraPosition.Builder()
.target(ll)
.zoom(finalMapZoom) // Sets the zoom
.build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Now, If I zoom in / out the marker moves from the actual place. If I just remove this
.anchor(0.5f, 0.5f));
Its working fine. The problem is I would like to put the marker in the upper/top position of the screen. So I used .anchor(0.5f, 4.8f)); which is also wrong according to the documentation . The value should be less or equal to 1.
Any ideas to resolve this issue??
Thanks in Advance.