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.
Related
I have a list of coordinates (yLat, xLon) with an angle (bearing in degrees, e.g. 160) to draw on my map, and I would like to do it with lines or arrows which start from the coordinates and head to the bearing.
I started to do it using a Polyline:
LatLng thisPoint = new LatLng(yLat, xLon);
Polyline site = googleMap.addPolyline(new PolylineOptions()
.add(thisPoint, new LatLng(11.593, 104.932))
.width(5)
.color(Color.MAGENTA));
However the line is too small when I zoom out: I want the line to be always the same size on the screen to show the direction to the user and independently of the zoom level.
See the example below: on the first screenshot the magenta line is big enough, but on the second one after zooming out, the line becomes smaller and we cannot see the direction as clearly.
Any suggestion?
I found the best way to address my need: I created a marker with an icon with a vertical arrow in the middle of a transparent square (R.mipmap.ic_arrow_up), then I create the marker applying a rotation of the desired angle:
googleMap.addMarker(new MarkerOptions()
.position(myLatLng)
.title(myTitle)
.snippet(mySnippet)
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_arrow_up))
.rotation(myAngle));
Hope this helps other people
I want to get the LatLng of the top right corner and bottom left corner of a Google Map frame to create a LatLngBounds. Is it possible to do that?
This can easily be determined using the Map View API:
yourMapFragment.getMap().getProjection().getVisibleRegion().latLngBounds
Which the docs state is:
The smallest bounding box that includes the visible region defined in this class.
Alternatively, you can also get the individual corners of the projection by replacing latLngBounds with farLeft, farRight, nearLeft or nearRight
In your case, you can simply use
LatLng bottomLeft =
yourMapFragment.getMap().getProjection().getVisibleRegion().nearLeft;
LatLng topRight =
yourMapFragment.getMap().getProjection().getVisibleRegion().farRight;
Of course. You have the Visible Region Object, that has the coordinates of all the four angles. Please refer to documentation.
(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.
I use android-maps-utils and I would like to know if this scenario is possible:
MapFragment is running and pins/marker are clustered
User go to list of markers and go to detail of chosen marker
User go from details to map and would like to see chosen marker centered and de-clustered
Is it possible to adjust zoom level to de-cluster cluster marker and display chosen marker?
//this line will zoom to specific point
map.animateCamera(CameraUpdateFactory.newLatLng(fault.getPosition()),
null);
I do not know how to de-cluster/zoom to display specific pin, without setting max/min zoom
Try this to adjust zoom level to de-cluster cluster marker:
LatLngBounds.Builder builder = LatLngBounds.builder();
for (ClusterItem item : cluster.getItems()) {
builder.include(item.getPosition());
}
final LatLngBounds bounds = builder.build();
getMap().animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
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