Skip to content

Instantly share code, notes, and snippets.

@William-ST
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save William-ST/7ca95340790e4d415698 to your computer and use it in GitHub Desktop.

Select an option

Save William-ST/7ca95340790e4d415698 to your computer and use it in GitHub Desktop.
package com.example.usuario.mapa;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity {
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment supportMapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = supportMapFragment.getMap();
googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title(latLng.latitude + " : " + latLng.longitude);
googleMap.clear();
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.addMarker(markerOptions);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment