Add marker on map ANDROID

0

Good evening, I have an application with a map on a swipe tab, but I want the map to mark a point on the map and start at that point.

Thank you in advance.

JAVA submission:

public class Mapa extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View android = inflater.inflate(R.layout.mapa_3, container, false);

    return android;
}

@Override
public void onDestroyView() {
    super.onDestroyView();
    Fragment f = getFragmentManager().findFragmentById(R.id.mapFragment);
    if (f != null)
        getFragmentManager().beginTransaction().remove(f).commit();
}

}

and the layout:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/map_container"
    tools:context=".Mapa" >

    <fragment 
        android:id="@+id/mapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>
    
asked by anonymous 30.07.2014 / 23:45

1 answer

1

Try this out

private void initilizeMap() {
        googleMap = ((SupportMapFragment) getFragmentManager()
                .findFragmentById(R.id. mapFragment)).getMap();

            googleMap.setMyLocationEnabled(true);
            googleMap.getUiSettings().setRotateGesturesEnabled(true);
            googleMap.getUiSettings().setZoomControlsEnabled(false);

            createMarkers();
    }

private void createMarkers() {
MarkerOptions marker = new MarkerOptions().position(
                new LatLng(lat, lon)).icon(
                BitmapDescriptorFactory
                        .fromResource(R.drawable.pin_localizacao));
        googleMap.addMarker(marker);


 }
    
31.07.2014 / 14:14