After starting new project, i've faced a problem with zooming maps in google maps v2 in android. I can't zoom map using default controls. The following code shows Camera position changing
CameraPosition currentPlace = new CameraPosition.Builder()
.target(mMarker.getPosition())
.bearing(bearing)
.zoom(14f) //apply zoom here
.build();
map.moveCamera(CameraUpdateFactory.newCameraPosition(currentPlace));
After this function i cannot zoom map with default controls
The solution to this problem is that we should use markers zoom when we move camera :
CameraPosition currentPlace = new CameraPosition.Builder()
.target(mMarker.getPosition()).bearing(bearing)
.zoom(map.getCameraPosition().zoom)
.build();
map.moveCamera(CameraUpdateFactory.newCameraPosition(currentPlace));
Try this,
get the location longitude and latitude
static LatLng loc1 = new LatLng(6.9009960, 79.8548823);
//zoom the location
map.moveCamera(CameraUpdateFactory.newLatLngZoom(loc1, 15));
Related
I am using Google Map API in an Android app and trying to rotate the map. I have already done it by changing the bearing value but the problem is that it rotates around the center of the screen.
CameraPosition bottomPos = new CameraPosition.Builder()
.bearing(bearing)
.build();
mainMap.animateCamera(CameraUpdateFactory.newCameraPosition(bottomPos));
I want to change its axis of rotation and make it rotate around a point at bottom of screen
Is there any function to change the axis of rotation of the map?
Anyway, you can use workaround like that - move map rotation center point to bottom of screen by creating MapView (MapFragment) twice as wide and as high and using margins align it position to center bottom like on a figure below:
In that case, with default:
CameraPosition bottomPos = new CameraPosition.Builder()
.bearing(bearing)
.build();
mainMap.animateCamera(CameraUpdateFactory.newCameraPosition(bottomPos));
your mainMap will turn around center of bottom of screen.
UPDATE:
Also you can use get current map center screen coordinates, then change y coordinate and get new screen center. Something like that:
...
CameraPosition bottomPos = new CameraPosition.Builder()
.bearing(bearing)
.build();
mainMap.moveCamera(CameraUpdateFactory.newCameraPosition(bottomPos));
LatLng mapCenter = mainMap.getCameraPosition().target;
Projection projection = mainMap.getProjection();
Point centerPoint = projection.toScreenLocation(mapCenter);
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int displayHeight = displayMetrics.heightPixels;
centerPoint.y = centerPoint.y - displayHeight / 2; // move center down
LatLng newCenterPoint = projection.fromScreenLocation(centerPoint);
mainMap.animateCamera(CameraUpdateFactory.newLatLngZoom(newCenterPoint, zoom));
...
I need to add a list of geopoints as markers on top of my custom OSM map in my android device, the below code is a sample for showing up one marker.
GeoPoint startPoint = new GeoPoint(48.13, -1.63);
Marker startMarker = new Marker(map);
startMarker.setPosition(startPoint);
startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
map.getOverlays().add(startMarker);
Related: Customizing clickable area on a Marker in Google Maps v2 for Android
I have a number of icons inside an ArrayList, which are all custom icons with a drawable. The problem I have is that the clickable area is that of the default marker. I need to customize this clickable area to the same size of the default marker.
Here is my code to generate a set of markers on the map:
MarkerOptions options = new MarkerOptions();
for (Icon iconItem: icons) {
//Scale icon
int markerSize = 90;
Bitmap iconBitmap = BitmapFactory.decodeResource(getResources(), iconItem.resourceInt);
Bitmap scaledIconBitmap = Bitmap.createScaledBitmap(iconBitmap, markerSize, markerSize, false);
options.position(iconItem.location).title(iconItem.type);
Marker newMarker = gMap.addMarker(options);
newMarker.setIcon(BitmapDescriptorFactory.fromBitmap(scaledIconBitmap));
}
Hi I wanted to know how I can slowly zoom in on a marker in a map activity in android. Currently my app just opens zoomed in on the marker. I would like it to zoom in slowly when the app is opened.
This is my current code
LatLng mark = new LatLng(21.197384, 6.369441);
mMap.addMarker(new MarkerOptions().position(mark).title("Marker for Mark"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
Use mMap.animateCamera instead of mMap.moveCamera
Also, you can control the duration of the movement using
animateCamera (CameraUpdate update, int durationMs, GoogleMap.CancelableCallback callback)
In your example, change
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
for
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
or, if you want the movement to last 200ms:
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel), 200, null);
Try mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel)); instead of
mMap.moveCamera(CameraUpdateFactory.newLatLng(mark));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mark, zoomLevel));
In this way you can achieve this --
CameraUpdate center= CameraUpdateFactory.newLatLng(new LatLng(latitude_origin, longitude_origin));
CameraUpdate zoom = CameraUpdateFactory.newLatLngZoom(new LatLng(latitude_origin, longitude_origin),3);
googleMap.animateCamera(center);
googleMap.animateCamera(zoom);
Hope this helps!
i have a place coordinate, i mean altitude and longitude , and i want to show this place with google map in android application, so how can i use this altitude and longitude to pass in a function and show that place in the app, i don't need to show current place , i have this longitudes and altitudes from before,and i save theme as a string in my application , is there any function or layout to show this place with this coordinates in application ? or i have to use some different method to show this places on map?
private GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.addMarker(new MarkerOptions()
.position(new LatLng(10, 10))
.title("Hello world"));
You could try:
String urlAddress = "http://maps.google.com/maps?q="+ lattitude string +"," + longitude_string +"("+ "Hello location" + ")&iwloc=A&hl=es";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress));
startActivity(intent);
This will open google maps with whatever coordinates you provide.