1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Marker;
import android.widget.Toast;
public static void CustomMap() {
MapView mapView = (MapView) getView("CARTE_Accueil");
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng PARIS = new LatLng(48.858093, 2.294694);
//ajoute un marker sur Paris
googleMap.addMarker(new MarkerOptions().title("Paris").position(PARIS));
//centre la google map sur Paris (avec animation de zoom)
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(PARIS, 15));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Toast.makeText(getContexteApplication(), marker.getTitle(), Toast.LENGTH_LONG).show();
}
});
}
});
} |
Partager