Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to zoom and add marker to android mapfragment

I am displaying a map at my android application (google maps api v2). I want to manipulate the map in order to show a specific location, zoom and marker.

can anyone give an example of manipulation mapfragment

like image 462
Reven Avatar asked Apr 01 '13 09:04

Reven


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.


1 Answers

To get map instance in code do this:

map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

or:

map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

depending on whether you used SupportMapFragment or MapFragment in your XML file.

Then to add a marker to it:

Marker newmarker = map.addMarker(new MarkerOptions().position(latlng).title("marker title").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_for_map_purpul)));

To zoom the map:

CameraPosition cameraPosition = new CameraPosition.Builder().target(latlng).zoom(14.0f).build();
CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition);
map.moveCamera(cameraUpdate);   
like image 80
Emil Adz Avatar answered Oct 22 '22 08:10

Emil Adz