android change bounds of google map - android

I am working on a project in android which requires me to change the bounds of a google map(from bottom only). Currently I am trying by adding padding at the bottom, but this process is slow and the screen also flickers.
Is there any better way to do this?
I would like the user to be able to drag the bottom of the map to change the bounds.
I see a lot of AJAX/JS resouces, but this is a native component.
Best

I think it will be a huge amount of work to let the user actually drag the bottom of your map view. what is much easier and faster to do is to create to 2 map fragments of your map and on click of the map change the fragment back and foreword between the two.
this way the user can change the size of the map the he works with.

You can zoom map to added points.
Here is some pseudo code:
LatLngBounds.Builder bc = new LatLngBounds.Builder();
for (LatLng item : points) {
bc.include(item);
}
LatLngBounds bounds = bc.build();
#SuppressWarnings("deprecation")
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds,
getWindowManager().getDefaultDisplay().getWidth(),
getWindowManager().getDefaultDisplay().getHeight(), 50);
mMap.moveCamera(cu);
Bounds will be changed to added points. Help It hope

Related

Change Google Map Offset Center

I'm trying to set the user location on the map such that it sits about 1/3 of the way up from the bottom of the screen, and when the map rotates, it will rotate around this point.
The closest I've got to achieving this is by using the setPadding() method, however, this causes the map to sort of shake when rotated, as the center point sort of 'floats' around where it actually should be. It looks quite ugly
int mapHeight = mapView.getHeight();
googleMap.setPadding(0, mapHeight / 5, 0, 0);
Is there a better way to do this?
Edit: Explained in picture below
You don't need paddings
Change mappoint X and Y values as you need you can call this where you want! may be inside your onLocationChanged like changeOffsetCenter(location.getLatitude(),location.getLongitude());
public void changeOffsetCenter(double latitude,double longitude) {
Point mappoint = mGoogleMap.getProjection().toScreenLocation(new LatLng(latitude, longitude));
mappoint.set(mappoint.x, mappoint.y-100); // change these values as you need , just hard coded a value if you want you can give it based on a ratio like using DisplayMetrics as well
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(mGoogleMap.getProjection().fromScreenLocation(mappoint)));
}
output :
Google map v3 beta seems to fix it, using padding now properly move pivotX/pivotY for rotation
https://developers.google.com/maps/documentation/android-sdk/v3-client-migration
Accepted answer might be work of "animateCamera". Its makes "shaking of rotations" almost invisible. So more easy will be using
mMap.setPadding(leftPx, topPx, rightPx, bottomPx)
with mMap.animateCamera
or twice mMap.moveCamera(in case of changing bearing
1nd moveCamera rotate with center of device, 2nd moveCamera make correct center using padding)
Its kind of hack, while google do not fix rotation considering setPadding

Force animateCamera to complete animation

I'm trying to force the camera to animate to a zoom level and coordinate that describes as precisely as possible the area occupied by a list of LatLng coordinates.
So far, I have the following:
private void focusListOfCoords(Collection<LatLng> coords) {
LatLngBounds.Builder coordsBoundsBuilder = new LatLngBounds.Builder();
for (LatLng coord : coords) {
coordsBoundsBuilder.include(coord);
}
LatLngBounds coordsBounds = coordsBoundsBuilder.build();
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(coordsBounds, 50);
mMap.animateCamera(cameraUpdate);
}
The code above, when zoomed all the way out on the whole world simply pans the view slightly to center on the center point of the bounds. It does not zoom in.
If I replace mMap.animateCamera(cameraUpdate) with mMap.moveCamera(cameraUpdate), the projection changes the zoom level (too far in every case, but that's beside the point) and centers as expected.
After trying to troubleshoot this, I noticed that if I implement the CancelableCallback for the animateCamera method, I can see that the animation is being cancelled.
Is there a way to force the animation to finish? If not, how can I hunt down the cause of the animation being cancelled?
Edit: The solution can be found in this question: Android- animateCamera with CameraUpdateFactory.newCameraPosition does NOT zoom
To summarize, my listener method that was calling the animation was returning false which cancelled the animation.
You can try to use a different approach to your implementation.
One is passing CameraUpdateFactory.newLatLngZoom(latlng, zoom) to animateCamera. You can specify the zoom level using this. More info on that here.
Or you can build your CameraView first before passing it to animateCamera. You can check out the docs here.
Not really sure why or how it is trigerring onCancel(). Maybe something is being fired right after your animateCamera call. Try to use the duration parameter to alter the speed of the animation and check for changes.

Cant Zoom Desired Level In Google Maps To Fit 2 Directions In Screen

(I would want to put screenshots put my reputation is low to put them...)
Good Day.I Have two directions(markers) on google maps api(android) between which i want camera to be center,and camera being centered there.But problem is that one marker comes to one edge of screen and another marker to another edge of screen!I don't want it to be like that,i want just to zoom specified level so markers will be center in google maps view and won't be place on edges of screen.I tried to put even 0 zoom level in camera update factory of google maps,but nothing happens at all.Here is my code how do i achieve that
} finally {
com.google.android.gms.maps.model.LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
boundsBuilder.include(new LatLng(Double.parseDouble(tolat), Double.parseDouble(tolong)));
boundsBuilder.include(new LatLng(Double.parseDouble(fromlat), Double.parseDouble(fromlong)));
final LatLngBounds bounds = boundsBuilder.build();
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
}
you say you tried to put 0 as the zoom level. You mean this call CameraUpdateFactory.newLatLngBounds(bounds, 0) right?
The second parameter is the padding not the zoom level. Set it up (example to 10) and you have a padding to the outer edges.
https://developers.google.com/android/reference/com/google/android/gms/maps/CameraUpdateFactory
I hope it helps.

Google Maps Android V2 padding with rotation around user

I'm developing an app that is using a google map to show your location. I want to rotate the map around the users location. I use getOrientation(R, orientation) (and adjust for true north) to get the device rotation which is working fine but i want the user location to be near the bottom of the screen. I have set the padding on the map to a quarter of the screen height
mMap.setPadding(0,screenHeight/4,0,0);
What hI have noticed is that the rotation is still done around the point at the centre of the screen NOT the padded centre.
This is the code I'm using in onSensorChanged
currentZoom = mMap.getCameraPosition().zoom;
CameraPosition currentPlace = new CameraPosition.Builder()
.target(new LatLng(currentNode.getLatitude(), currentNode.getLongitude()))
.bearing(degrees).tilt(60).zoom(currentZoom).build();
mMap.stopAnimation();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(currentPlace),40,null);
Is there a way to change the anchor point of camera rotation?
I was trying to solve this problem for several hours. The only solution I found is not very good, but it works:
For example, if you want to move the user 200dp below the center:
1) Set map fragment height to its height + 200dp (Then the map will go 200dp below the screen)
2) This works fine, but it hides Google logo. To preserve the Google logo, set map padding top and bottom to 200dp.
mGoogleMap.setPadding(0, dp2px(200),0 , dp2px(200));
That solves the problem

Android Google Maps - show half the earth

I want to display a google map in my application that shows one complete half of the globe, containing two markers that are about 20,000 km from one another in the same view.
I tried using the property getMinZoomLevel(), but it's not sufficient - it shows the first marker surrounded by an area only about the size of half a continent. Is there any way of getting the wide view that I want?
Code example for last known user location (one of the markers), where zoomLevel is getMinZoomLevel():
map.moveCamera(CameraUpdateFactory.newCameraPosition(getCameraPositionFromLocationWithZoom(UserLocation.getInstance(App.getInstance().getApplicationContext()).getLastKnownLocation(), zoomLevel)));
Try something like.
private LatLngBounds bounds;
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(pointA);
builder.include(pointB);
//and other latlng points as you like...
bounds = builder.build();
map.animateCamera(CameraUpdateFactory.newLatLngBounds(
bounds, 20));
animateCamera animates the camera to specific point location. if you have more then one point (LatLngBounds) it will expand the map to be visible all points.
Hope to be helpful.

Categories

Resources