com.google.android.gms.maps.MapsInitializer Java Examples

The following examples show how to use com.google.android.gms.maps.MapsInitializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Mapa.java    From android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mapa);

    // Recoge los datos enviados por la Activity que la invoca
    Intent i = getIntent();
    latitud = i.getFloatExtra("latitud", 0);
    longitud = i.getFloatExtra("longitud", 0);
    nombre = i.getStringExtra("nombre");

    // Transforma las coordenadas al sistema LatLng y las almacena
    uk.me.jstott.jcoord.LatLng ubicacion = Util.DeUMTSaLatLng(latitud, longitud, 'N', 30);
    this.latitud = ubicacion.getLat();
    this.longitud = ubicacion.getLng();

    // Inicializa el sistema de mapas de Google
    try {
        MapsInitializer.initialize(this);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Obtiene una referencia al objeto que permite "manejar" el mapa
    mapa = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
 
Example #2
Source File: SwipeableCard.java    From SwipeableCard with Apache License 2.0 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    mGoogleMap = googleMap;
    MapsInitializer.initialize(getContext());
    googleMap.getUiSettings().setMapToolbarEnabled(true);
    if (mMapLocation != null && !mOptionView.isMultipleMarker() && mOptionView.isSingleMarker()) {
        updateMapContents();
    }
    if(mOptionView.getLatLngArray() != null && mOptionView.getLatLngArray().length > 0 && mOptionView.isMultipleMarker() && !mOptionView.isSingleMarker())
    {
        updateMapContents();
    }
    if(mOptionView.getLatLngList() != null && mOptionView.getLatLngList().size() > 0 && mOptionView.isMultipleMarker() && !mOptionView.isSingleMarker())
    {
        updateMapContents();
    }
}
 
Example #3
Source File: GeoPointMapActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap map) {
    this.map = map;

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED ||
            ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        map.getUiSettings().setMyLocationButtonEnabled(true);
        map.setMyLocationEnabled(true);
        map.setOnMyLocationButtonClickListener(this);
    }

    MapsInitializer.initialize(this);

    if (location.hasAccuracy()) {
        drawMarker();
    }
    setupMapListeners();

    map.setMapType(HiddenPreferences.getMapsDefaultLayer().getValue());
}
 
Example #4
Source File: LocationPickerDialog.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHandler = new Handler();
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.location_picker_dialog);
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    try {
        MapsInitializer.initialize(this);
    } catch (Exception e) {
        e.printStackTrace();
    }

    mMap = ((SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map)).getMap();

    mMap.setMyLocationEnabled(true);

    if ( getIntent().getParcelableExtra("location") != null ) {
        final CameraPosition newPosition = CameraPosition.fromLatLngZoom((LatLng) getIntent().getParcelableExtra("location"), 15);

        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mMap.animateCamera(CameraUpdateFactory.newCameraPosition(newPosition));
            }
        }, 500);
    }

    findViewById(R.id.save).setOnClickListener(this);
    findViewById(R.id.cancel).setOnClickListener(this);
}
 
Example #5
Source File: PlaceOnAMapDialog.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle args = getIntent().getExtras();
    this.title = args.getString("title", null);
    this.location = args.getParcelable("location");

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    setContentView(R.layout.dialog_place_on_a_map);

    TextView textViewTitle = (TextView) findViewById(R.id.dialog_title);
    if (this.title != null)
        textViewTitle.setText(this.title);
    else
        textViewTitle.setText(location.latitude + ", " + location.longitude);

    try {
        MapsInitializer.initialize(this);
    } catch (Exception e) {
        e.printStackTrace();
    }

    map = ((SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map)).getMap();

    map.getUiSettings().setScrollGesturesEnabled(false);
    map.getUiSettings().setZoomGesturesEnabled(false);
    map.getUiSettings().setRotateGesturesEnabled(false);

    map.addMarker(new MarkerOptions()
            .position(location));

    CameraPosition newPosition = CameraPosition.fromLatLngZoom(location, 12.0f);
    map.moveCamera(CameraUpdateFactory.newCameraPosition(newPosition));
}
 
Example #6
Source File: AtlasFragment.java    From memoir with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_atlas, container, false);

    MapsInitializer.initialize(getActivity());
    mMapView = (MapView) v.findViewById(R.id.map_view);
    mMapView.onCreate(mBundle);
    mMapView.getMapAsync(this);

    return v;
}
 
Example #7
Source File: RecyclerViewLiteModeAdapter.java    From Airbnb-Android-Google-Map-View with MIT License 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    MapsInitializer.initialize(mContext);
    map = googleMap;
    isMapReady=true;
    map.getUiSettings().setMapToolbarEnabled(false);

    if (mapView.getViewTreeObserver().isAlive()) {
        mapView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @SuppressWarnings("deprecation") // We use the new method when supported
            @SuppressLint("NewApi") // We check which build version we are using.
            @Override
            public void onGlobalLayout() {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                    mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                } else {
                    mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
                //  showBoth(null);
            }
        });
    }
    try{
        setMapData(new LatLng(Double.parseDouble(addressModel.getLatitude()),Double.parseDouble(addressModel.getLongitude())));
    }catch(Exception e){
        e.printStackTrace();
    }


    //  mapInterface.mapIsReadyToSet(this,position);
}
 
Example #8
Source File: Venue.java    From mConference-Framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_venue, container,
            false);
    MapsInitializer.initialize(getActivity().getApplicationContext());
    scrollView = (ScrollView) v.findViewById(R.id.venue_scrollview);
    mMapView = (VenueMapView) v.findViewById(R.id.mapView);
    TextView address = (TextView) v.findViewById(R.id.venue_detail);

    sharedPref = getActivity().getApplicationContext()
            .getSharedPreferences(PREFERENCES_FILE_NAME, Context.MODE_PRIVATE);
    venueAddress = sharedPref.getString(VENUE_TAG, null);
    address.setText(venueAddress);
    mMapView.onCreate(savedInstanceState);

    mMapView.onResume();// needed to get the map to display immediately

    status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity().getApplicationContext());

    googleMap = mMapView.getMap();

    new MapPlotting().execute();

    return v;
}
 
Example #9
Source File: Android_Mapas.java    From android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_android__mapas);
    
    listaGasolineras = new ArrayList<Gasolinera>();
    adapter = new GasolineraAdapter(this, R.layout.item, listaGasolineras);
    
    spGasolineras = (Spinner) findViewById(R.id.spGasolineras);
    spGasolineras.setAdapter(adapter);
    
    btVerGasolinera = (Button) findViewById(R.id.btVerGasolinera);
    btVerGasolinera.setOnClickListener(this);
    btLimpiar = (Button) findViewById(R.id.btLimpiar);
    btLimpiar.setOnClickListener(this);
    
    // Inicializa el sistema de mapas de Google
    //try {
        MapsInitializer.initialize(this);
    /*} catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
    }*/
    
    // Obtiene una referencia al objeto que permite "manejar" el mapa
    mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    
    cargarListaGasolineras();
}
 
Example #10
Source File: GeofieldFragment.java    From mobile-android-survey-app with MIT License 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    Log.i(this, "onMapReady %s", googleMap);
    MapsInitializer.initialize(getActivity());
    map = googleMap;
    if (map != null) {
        map.setOnMapClickListener(this);
        map.setOnMarkerDragListener(this);
        map.setOnMapLongClickListener(this);
    }
}
 
Example #11
Source File: MapLocationViewHolder.java    From android-map_list with MIT License 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    mGoogleMap = googleMap;

    MapsInitializer.initialize(mContext);
    googleMap.getUiSettings().setMapToolbarEnabled(false);

    // If we have map data, update the map content.
    if (mMapLocation != null) {
        updateMapContents();
    }
}
 
Example #12
Source File: KmlStyleTest.java    From android-maps-utils with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    MapsInitializer.initialize(ShadowInstrumentation.getInstrumentation().getTargetContext());
}
 
Example #13
Source File: GeoJsonPointStyleTest.java    From android-maps-utils with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    MapsInitializer.initialize(InstrumentationRegistry.getInstrumentation().getTargetContext());
    pointStyle = new GeoJsonPointStyle();
}
 
Example #14
Source File: MapFactory.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
public static IMap getMap(final com.google.android.gms.maps.MapView aMapView) {
	final GoogleMap map = aMapView.getMap();
	MapsInitializer.initialize(aMapView.getContext());
	return map != null ? new MapWrapper(map) : null;
}
 
Example #15
Source File: Mapa.java    From android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
       setContentView(R.layout.mapa);
	
	Button btGuardarPosicion = (Button) findViewById(R.id.btGuardarPosicion);
	btGuardarPosicion.setOnClickListener(this);
	Button btVerMiPosicion = (Button) findViewById(R.id.btVerMiPosicion);
	btVerMiPosicion.setOnClickListener(this);
	Button btDistancia = (Button) findViewById(R.id.btDistancia);
	btDistancia.setOnClickListener(this);
	
	// Inicializa el sistema de mapas de Google
       MapsInitializer.initialize(this);
       
       // Obtiene una referencia al objeto que permite "manejar" el mapa
       mapa = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
       mapa.setOnMarkerClickListener(this);
       
       // Comprueba si hay que mostrar una gasolinera o toda la lista
       String accion = getIntent().getStringExtra("accion");
       if (accion.equals("gasolinera")) {
        Gasolinera gasolinera = getIntent().getParcelableExtra("gasolinera");
        if (gasolinera != null)
        	marcarGasolinera(gasolinera);
       }
       else if (accion.equals("gasolineras")){
       	ArrayList<Gasolinera> gasolineras = getIntent().getParcelableArrayListExtra("gasolineras");
       	if (gasolineras != null) {
       		marcarGasolineras(gasolineras);
       	}
       }
       else if (accion.equals("ubicacion")) {
           Ubicacion ubicacion = getIntent().getParcelableExtra("ubicacion");
           if (ubicacion != null)
               marcarUbicacion(ubicacion);
       }
       else if (accion.equals("ubicaciones")) {
           ArrayList<Ubicacion> ubicaciones = getIntent().getParcelableArrayListExtra("ubicaciones");
           if (ubicaciones != null) {
               marcarUbicaciones(ubicaciones);
           }
       }
       else {
       	// Sólo mostrar mapa, no hacer nada
       }
       
       // Activa el botón para localizar mi posición
       mapa.setMyLocationEnabled(true);
       
       database = new Database(this);
       
       // Configura el gestor de localizaciones
       configuraLocalizador();
}
 
Example #16
Source File: LiteListDemoActivity.java    From android-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    MapsInitializer.initialize(getApplicationContext());
    map = googleMap;
    setMapLocation();
}
 
Example #17
Source File: MapFragment.java    From mage-android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater  inflater, ViewGroup container, Bundle savedInstanceState) {
	View view = inflater.inflate(R.layout.fragment_map, container, false);

	setHasOptionsMenu(true);

	staticGeometryCollection = new StaticGeometryCollection();

	availableLayerDownloadsIcon = view.findViewById(R.id.available_layer_downloads);
	zoomToLocationButton = view.findViewById(R.id.zoom_button);

	compassButton = view.findViewById(R.id.compass_button);
	compassButton.setOnClickListener(v -> resetMapBearing());

	searchButton = view.findViewById(R.id.map_search_button);
	if (Geocoder.isPresent()) {
		searchButton.setOnClickListener(v -> search());
	} else {
		searchButton.hide();
	}

	view.findViewById(R.id.new_observation_button).setOnClickListener(v -> onNewObservation());

	searchLayout = view.findViewById(R.id.search_layout);
	searchView = view.findViewById(R.id.search_view);
	searchView.setIconifiedByDefault(false);
	searchView.setIconified(false);
	searchView.clearFocus();

	MapsInitializer.initialize(context);

	ImageButton mapSettings = view.findViewById(R.id.map_settings);
	mapSettings.setOnClickListener(this);

	mapView = view.findViewById(R.id.mapView);
	Bundle mapState = (savedInstanceState != null) ? savedInstanceState.getBundle(MAP_VIEW_STATE): null;
	mapView.onCreate(mapState);

	mgrsBottomSheet = view.findViewById(R.id.mgrs_bottom_sheet);
	mgrsBottomSheetBehavior = BottomSheetBehavior.from(mgrsBottomSheet);
	mgrsCursor = view.findViewById(R.id.mgrs_grid_cursor);
	mgrsTextView = mgrsBottomSheet.findViewById(R.id.mgrs_code);
	mgrsGzdTextView = mgrsBottomSheet.findViewById(R.id.mgrs_gzd_zone);
	mgrs100dKmTextView = mgrsBottomSheet.findViewById(R.id.mgrs_grid_zone);
	mgrsEastingTextView = mgrsBottomSheet.findViewById(R.id.mgrs_easting);
	mgrsNorthingTextView = mgrsBottomSheet.findViewById(R.id.mgrs_northing);

	// Initialize the GeoPackage cache with a GeoPackage manager
	GeoPackageManager geoPackageManager = GeoPackageFactory.getManager(getActivity().getApplicationContext());
	geoPackageCache = new GeoPackageCache(geoPackageManager);

	locationProvider = locationPolicy.getBestLocationProvider();

	return view;
}
 
Example #18
Source File: TrackFragment.java    From kute with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.trackfragment, container, false);

    mMapView = (MapView) rootView.findViewById(R.id.mapView);
    mMapView.onCreate(savedInstanceState);

    mMapView.onResume(); // needed to get the map to display immediately

    try {
        MapsInitializer.initialize(getActivity().getApplicationContext());
    } catch (Exception e) {
        e.printStackTrace();
    }

    mMapView.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap mMap) {
            googleMap = mMap;


            // For showing a move to my location button
            if (ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
            googleMap.setMyLocationEnabled(true);

            // For dropping a marker at a point on the Map
            LatLng sydney = new LatLng(-34, 151);
            googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker Title track").snippet("Marker Description"));

            // For zooming automatically to the location of the marker
            CameraPosition cameraPosition = new CameraPosition.Builder().target(sydney).zoom(12).build();
            googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
        }
    });

    return rootView;
}
 
Example #19
Source File: PublishFragment.java    From kute with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.publishfragment, container, false);

    mMapView = (MapView) rootView.findViewById(R.id.mapViewpublish);
    mMapView.onCreate(savedInstanceState);

    mMapView.onResume(); // needed to get the map to display immediately

    try {
        MapsInitializer.initialize(getActivity().getApplicationContext());
    } catch (Exception e) {
        e.printStackTrace();
    }

    mMapView.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap mMap) {
            googleMap = mMap;


            // For showing a move to my location button
            if (ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
            googleMap.setMyLocationEnabled(true);

            // For dropping a marker at a point on the Map
            LatLng sydney = new LatLng(-34, 151);
            googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker Title Publish").snippet("Marker Description"));

            // For zooming automatically to the location of the marker
            CameraPosition cameraPosition = new CameraPosition.Builder().target(sydney).zoom(12).build();
            googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
        }
    });

    return rootView;
}
 
Example #20
Source File: GridAdapter.java    From snazzymaps-browser with Apache License 2.0 4 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    MapsInitializer.initialize(mContext.getApplicationContext());
    map = googleMap;
    initializeMap(map, (SnazzyMapsStyle) mapView.getTag());
}
 
Example #21
Source File: LocalPlacesAdapter.java    From ratebeer with GNU General Public License v3.0 4 votes vote down vote up
public LocalPlacesAdapter(Context context, List<LocalPlace> places) {
	this.useMetricUnits = Session.get().useMetricUnits();
	this.unitString = context.getString(useMetricUnits ? R.string.place_km : R.string.place_miles);
	this.places = places;
	MapsInitializer.initialize(context);
}
 
Example #22
Source File: PlacesFragment.java    From narrate-android with Apache License 2.0 4 votes vote down vote up
private void setup() {
    mSheetAdapter = new EntriesRecyclerAdapter(mainActivity.entries);

    mapView = (MapView) mRoot.findViewById(R.id.mapView);
    mapView.setAlwaysDrawnWithCacheEnabled(true);
    mapView.setPersistentDrawingCache(MapView.PERSISTENT_ALL_CACHES);
    mapView.onCreate(null);

    try {
        MapsInitializer.initialize(getActivity().getApplicationContext());
    } catch (Exception e) {
        e.printStackTrace();
    }

    map = mapView.getMap();

    mClusterManager = new ClusterManager<EntryMarker>(getActivity(), map);
    map.setOnCameraChangeListener(mClusterManager);
    map.setOnMarkerClickListener(mClusterManager);

    mClusterManager.setOnClusterClickListener(this);
    mClusterManager.setOnClusterItemClickListener(this);

    onDataUpdated();

    if (ActivityCompat.checkSelfPermission(mainActivity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mainActivity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        map.setMyLocationEnabled(false);

        if ( getActivity() != null && getActivity().getSystemService(Context.LOCATION_SERVICE) != null) {
            String locationProvider = LocationManager.NETWORK_PROVIDER;
            LocationManager mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
            lastKnownLocation = mLocationManager.getLastKnownLocation(locationProvider);
        }

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if ( !isAdded() )
                    return;

                if ( lastKnownLocation != null ) {
                    LatLng position = new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude());
                    CameraPosition newPosition = CameraPosition.fromLatLngZoom(position, 12.0f);
                    map.animateCamera(CameraUpdateFactory.newCameraPosition(newPosition));
                }

            }
        }, 500);
    }
}