Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center a map marker in Android

I use the following code to display a single marker at a zoom level but it doesn't center tha marker on the map. Only one marker will ever be shown:

LatLng latLng = new LatLng(Latitude, Longitude);
cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 11.0f);

This code will center it but it doesn't provide any zoom:

LatLngBounds bounds = latLngBuilder.build();
cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 30);

I need to center AND zoom.

like image 741
Johann Avatar asked Jul 12 '13 09:07

Johann


People also ask

How do I drag a marker on Google Maps Android?

Long press the marker to enable dragging. When you take your finger off the screen, the marker will remain in that position. Markers are not draggable by default. You must explicitly set the marker to be draggable either with MarkerOptions.

How do I rotate a marker on Google Maps?

If you create your custom marker using SVG it can be done quite easily using transform="rotate(deg centerX centerY") . Thanks, I found this The symbol's path, which is a built-in symbol path, or a custom path expressed using SVG path notation. Precisely, so you could add your own SVG-symbols using that.

How do I change the color of a marker on Google Maps?

To edit the marker color, click or tap on the marker icon. When you do that, you can change both the color of the marker and its style. Go for the color or style you want to change and then click OK to see the effect. Click on the button labeled Done to save your new marker color settings.


1 Answers

this is because you need to move you camera to the CameraUpdateFactory you created, like this:

LatLng latLng = new LatLng(Latitude, Longitude);
map.animateCamera(CameraUpdateFactory.newLatLng(latLng, 11);

if you don't want the animation, then you could just use:

map.moveCamera(CameraUpdateFactory.newLatLng(latLng, 11);
like image 155
Emil Adz Avatar answered Oct 04 '22 07:10

Emil Adz