Add Bookmark with click

1

How do I add a bookmark to the map with a click?

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_maps);


       // Obtain the SupportMapFragment and get notified when the map is ready to be used.
       SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
       mapFragment.getMapAsync(this);
}



   @Override
   public void onMapReady(GoogleMap googleMap) {
       mMap = googleMap;

      // Add a marker in Sydney and move the camera
       LatLng sydney = new LatLng(-34, 151);
       mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
       mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }


}
    
asked by anonymous 21.11.2016 / 20:25

1 answer

0

Within the onMapRead method, just use the setOnMapClickListener() method, including the Marker settings, passing latitude and longitude. See:

googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {

    @Override
    public void onMapClick(LatLng point) {
        // define latitude longitude e titulo do marker
        MarkerOptions marker = new MarkerOptions().position(
            new LatLng(point.latitude, point.longitude)).title("New Marker");
        // inclui um marker
        googleMap.addMarker(marker);

    }
});
    
08.09.2017 / 14:52