Add bookmark on map ANDROID

Asked

Viewed 819 times

0

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

thanks in advance.

Together send the JAVA:

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>
  • How are you handling the instance of GoogleMap? To create a Marker just create one MarkerOptions and then pass it on to GoogleMap.createMarker.

  • But this is done in java?

  • That’s right, no onCreate of Activity or of onCreateView of Fragment. Take a look at the first answer to this EN OS question: http://stackoverflow.com/questions/19353255/how-to-put-google-maps-v2-on-a-fragment-using-viewpager.

1 answer

1

Try this

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);


 }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.