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

The following examples show how to use com.google.android.gms.maps.MapFragment. 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: MapsEarthquakeMapActivity.java    From coursera-android with MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    if (null != savedInstanceState) {
        mRetainedFragment = (RetainedFragment) getFragmentManager()
                .findFragmentByTag(RetainedFragment.TAG);
        onDownloadfinished();
    } else {
        mRetainedFragment = new RetainedFragment();
        getFragmentManager().beginTransaction()
                .add(mRetainedFragment, RetainedFragment.TAG)
                .commit();
        mRetainedFragment.onButtonPressed();
    }

    // The GoogleMap instance underlying the GoogleMapFragment defined in main.xml
    MapFragment map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
    map.getMapAsync(this);
}
 
Example #3
Source File: BarometerNetworkActivity.java    From PressureNet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Zoom into the user's location
 */
public void setUpMap() {
	setUpMapIfNeeded();

	try {
		mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
				.getMap();

		// Set default coordinates (centered around the user's location)
		if(!fromActivityResult)  {
			appStartGoToMyLocation();
		}

	} catch(NullPointerException npe) {
		log("app can't set up map due to location problem");
		if(bestLocation == null) {

			displayMapToast("Location is unavailable for weather map");
		}
	}

}
 
Example #4
Source File: ObservationFormPickerActivity.java    From mage-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_observation_form_picker);

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.forms);

    FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(this);
    layoutManager.setFlexDirection(FlexDirection.ROW);
    layoutManager.setJustifyContent(JustifyContent.CENTER);
    recyclerView.setLayoutManager(layoutManager);

    JsonArray formDefinitions = EventHelper.getInstance(getApplicationContext()).getCurrentEvent().getNonArchivedForms();
    Adapter adapter = new Adapter(this, formDefinitions);
    recyclerView.setAdapter(adapter);

    findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cancel(v);
        }
    });

    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}
 
Example #5
Source File: MapActivity.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    // Set the layout. It only contains a SupportMapFragment and a DismissOverlay.
    setContentView(R.layout.activity_map);

    // Obtain the Attraction that we need to display.
    mAttraction = getIntent().getParcelableExtra(Constants.EXTRA_ATTRACTION);

    // Obtain the DismissOverlayView and display the intro help text.
    mDismissOverlay = (DismissOverlayView) findViewById(R.id.map_dismiss_overlay);
    mDismissOverlay.setIntroText(R.string.exit_intro_text);
    mDismissOverlay.showIntroIfNecessary();

    // Obtain the MapFragment and set the async listener to be notified when the map is ready.
    MapFragment mapFragment = (MapFragment) getFragmentManager()
                    .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}
 
Example #6
Source File: ShowLocationActivity.java    From ShareLocationPlugin with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	ActionBar actionBar = getActionBar();
	if (actionBar != null) {
		actionBar.setDisplayHomeAsUpEnabled(true);
	}

	setContentView(R.layout.show_locaction_activity);
	MapFragment fragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map_fragment);
	fragment.getMapAsync(this);
}
 
Example #7
Source File: BaseMapActivity.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
protected void initMapIfNecessary() {
    if( mGoogleMap != null ) {
        return;
    }

    mGoogleMap = ( (MapFragment) getFragmentManager().findFragmentById( R.id.map ) ).getMap();

    initMapSettings();
    initCamera();
}
 
Example #8
Source File: MainActivity.java    From RouteDrawer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

    final RouteDrawer routeDrawer = new RouteDrawer.RouteDrawerBuilder(googleMap)
            .withColor(Color.BLUE)
            .withWidth(8)
            .withAlpha(0.5f)
            .withMarkerIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))
            .build();

    RouteRest routeRest = new RouteRest();

    routeRest.getJsonDirections(new LatLng(50.126922, 19.015261), new LatLng(50.200206, 19.175603), TravelMode.DRIVING)
            .observeOn(AndroidSchedulers.mainThread())
            .map(new Func1<String, Routes>() {
                @Override
                public Routes call(String s) {
                    return new RouteJsonParser<Routes>().parse(s, Routes.class);
                }
            })
            .subscribe(new Action1<Routes>() {
                @Override
                public void call(Routes r) {
                    routeDrawer.drawPath(r);
                }
            });

}
 
Example #9
Source File: GoogleMapActivity.java    From coursera-android with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // The GoogleMap instance underlying the GoogleMapFragment defined in main.xml
    MapFragment map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
    map.getMapAsync(this);

}
 
Example #10
Source File: MainActivity.java    From xposed-gps with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	settings = new Settings(getApplicationContext());
	FragmentManager fm = getFragmentManager();
	Fragment frag = fm.findFragmentById(R.id.map);
	if (frag instanceof MapFragment) {
		MapFragment mapf = (MapFragment) frag;
		mMap = (GoogleMap) mapf.getMap();
		mMap.setOnCameraChangeListener(this);
		mMarker = new MarkerOptions();
		mInit = new LatLng(settings.getLat(), settings.getLng());
		mMarker.position(mInit);
		mMarker.draggable(true);

		CameraUpdate cam = CameraUpdateFactory.newLatLng(mInit);
		mMap.moveCamera(cam);
		mMap.addMarker(mMarker);
	}

	Button set   = (Button) findViewById(R.id.set_location);
	set.setOnClickListener(this);
	Button start = (Button) findViewById(R.id.start);
	start.setOnClickListener(this);
	Button sel   = (Button) findViewById(R.id.select_apps);
	sel.setOnClickListener(this);

	start.setText(settings.isStarted() ? getString(R.string.stop) : getString(R.string.start));
}
 
Example #11
Source File: DetailActivity.java    From google-io-2014 with Apache License 2.0 5 votes vote down vote up
private void setupMap() {
    GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

    double lat = getIntent().getDoubleExtra("lat", 37.6329946);
    double lng = getIntent().getDoubleExtra("lng", -122.4938344);
    float zoom = getIntent().getFloatExtra("zoom", 15.0f);

    LatLng position = new LatLng(lat, lng);
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(position, zoom));
    map.addMarker(new MarkerOptions().position(position));
}
 
Example #12
Source File: MapPickerActivity.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setUpMapIfNeeded() {
    // Do a null check to confirm that we have not already instantiated the map.
    if (mMap == null) {
        // Try to obtain the map from the SupportMapFragment.
        ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMapAsync(googleMap -> {
                    mMap = googleMap;
                    if (mMap != null) {
                        setUpMap();
                    }
                });

    }
}
 
Example #13
Source File: MainActivity.java    From TutosAndroidFrance with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mapFragment = (MapFragment) getFragmentManager()
            .findFragmentById(R.id.mapFragment);
    mapFragment.getMapAsync(this);
}
 
Example #14
Source File: BarometerNetworkActivity.java    From PressureNet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Move and animate the map to a new location
 * 
 * @param latitude
 * @param longitude
 */
private void moveMapTo(double latitude, double longitude) {


	mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
			.getMap();
	try {
		mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
				latitude, longitude), DEFAULT_ZOOM));
	} catch (Exception e) {
		// e.printStackTrace();
	}
}
 
Example #15
Source File: MapActivity.java    From Nimbus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);

    MapFragment mapFragment= (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

}
 
Example #16
Source File: MainActivity.java    From NYU-BusTracker-Android with Apache License 2.0 5 votes vote down vote up
private void setUpMapIfNeeded() {
    // First check if GPS is available.
    final LatLng BROADWAY = new LatLng(40.729146, -73.993756);
    int retCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
    if (retCode != ConnectionResult.SUCCESS) {
        GooglePlayServicesUtil.getErrorDialog(retCode, this, 1).show();
    }
    // Do a null check to confirm that we have not already instantiated the map.
    if (mMap == null) {
        MapFragment mFrag = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
        if (mFrag != null) mMap = mFrag.getMap();
        // Check if we were successful in obtaining the map.
        if (mMap != null) {
            // The Map is verified. It is now safe to manipulate the map.
            mMap.getUiSettings().setRotateGesturesEnabled(false);
            mMap.getUiSettings().setZoomControlsEnabled(false);
            mMap.setMyLocationEnabled(true);
            mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
                @Override
                public boolean onMarkerClick(Marker marker) {
                    return !clickableMapMarkers.get(marker.getId());    // Return true to consume the event.
                }
            });
            CameraUpdate center =
                    CameraUpdateFactory.newLatLng(BROADWAY);
            CameraUpdate zoom = CameraUpdateFactory.zoomTo(15);

            mMap.moveCamera(center);
            mMap.animateCamera(zoom);
        }
    }
}
 
Example #17
Source File: MainActivity.java    From video-tutorial-code with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	
	map  = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
	
	map.addMarker(new MarkerOptions().position(LOCATION_SURRREY).title("Find me here!"));
}
 
Example #18
Source File: MapActivity.java    From Bus-Tracking-Parent with GNU General Public License v3.0 4 votes vote down vote up
private void init() {
    MapFragment fragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map_frag);
    fragment.getMapAsync(this);
}
 
Example #19
Source File: MainActivity.java    From mil-sym-android with Apache License 2.0 4 votes vote down vote up
/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    FragmentManager f = getFragmentManager();
    mapFragment = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));       
    map = mapFragment.getMap();
    map.getUiSettings().setZoomControlsEnabled(true);
    map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
    map.setBuildingsEnabled(true);        
    if (myView == null) {
        myView = new MyView(this);
        myView.map = map;
    }
    utility.map = map;
    loadRenderer();

    editText = (EditText) findViewById(R.id.edit_message);
    editText.setTextColor(Color.RED);
    editText.setText("flot");
    map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng point) {
            //this should instead be set by an event handler for editText
            MyView.linetype = editText.getText().toString().toUpperCase(Locale.US);
            myView.onTouchEvent(point);
            return;
        }
    });
    map.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {

        private float currentZoom = -1;

        @Override
        public void onCameraChange(CameraPosition pos) {
            if (pos.zoom != currentZoom) {
                currentZoom = pos.zoom;
            }
            myView.setExtents();
            myView.DrawFromZoom(null);
        }
    }
    );
}
 
Example #20
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 #21
Source File: MainActivity.java    From android-samples with Apache License 2.0 4 votes vote down vote up
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    // Set the layout. It only contains a SupportMapFragment and a DismissOverlay.
    setContentView(R.layout.activity_main);

    // Enable ambient support, so the map remains visible in simplified, low-color display
    // when the user is no longer actively using the app but the app is still visible on the
    // watch face.
    setAmbientEnabled();

    // Retrieve the containers for the root of the layout and the map. Margins will need to be
    // set on them to account for the system window insets.
    final FrameLayout topFrameLayout = (FrameLayout) findViewById(R.id.root_container);
    final FrameLayout mapFrameLayout = (FrameLayout) findViewById(R.id.map_container);

    // Set the system view insets on the containers when they become available.
    topFrameLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            // Call through to super implementation and apply insets
            insets = topFrameLayout.onApplyWindowInsets(insets);

            FrameLayout.LayoutParams params =
                    (FrameLayout.LayoutParams) mapFrameLayout.getLayoutParams();

            // Add Wearable insets to FrameLayout container holding map as margins
            params.setMargins(
                    insets.getSystemWindowInsetLeft(),
                    insets.getSystemWindowInsetTop(),
                    insets.getSystemWindowInsetRight(),
                    insets.getSystemWindowInsetBottom());
            mapFrameLayout.setLayoutParams(params);

            return insets;
        }
    });

    // Obtain the DismissOverlayView and display the intro help text.
    mDismissOverlay = (DismissOverlayView) findViewById(R.id.dismiss_overlay);
    mDismissOverlay.setIntroText(R.string.intro_text);
    mDismissOverlay.showIntroIfNecessary();

    // Obtain the MapFragment and set the async listener to be notified when the map is ready.
    mMapFragment = (MapFragment) getFragmentManager()
            .findFragmentById(R.id.map);
    mMapFragment.getMapAsync(this);

}
 
Example #22
Source File: FenceChooserActivity.java    From JCVD with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fence_chooser);

    mRootView = findViewById(R.id.parent_layout);

    MapFragment map = (MapFragment) getFragmentManager()
            .findFragmentById(R.id.map);
    map.getMapAsync(this);

    mActivityType = new ArrayList<>();

    mGeofenceManager = new StorableFenceManager(this);
    mGeofenceManager.setListener(this);

    mFab = findViewById(R.id.fab);
    if (mFab != null) {
        mFab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StorableFence locationFence = null;
                StorableFence activityFence = null;
                StorableFence resultFence = null;
                if (mLocation != null) {
                    locationFence = StorableLocationFence.entering(mLocation.latitude,
                                    mLocation.longitude, 100);
                }

                if (!mActivityType.isEmpty()) {
                    @StorableActivityFence.ActivityType
                    int[] ret = new int[mActivityType.size()];
                    int i = 0;
                    for (int val : mActivityType) {
                        ret[i++] = val;
                    }
                    activityFence = StorableActivityFence.during(ret);
                }

                if (locationFence != null && activityFence != null) {
                    resultFence = StorableFence.and(locationFence, activityFence);
                } else if (locationFence != null) {
                    resultFence = locationFence;
                } else if (activityFence != null) {
                    resultFence = activityFence;
                }
                if (resultFence != null) {
                    if (ContextCompat.checkSelfPermission(FenceChooserActivity.this,
                            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                        mGeofenceManager.addFence(UUID.randomUUID().toString(), resultFence, null, CustomTransitionsIntentService.class.getName());
                    }
                }
            }
        });
    }

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                ACCESS_FINE_LOCATION_REQUEST_CODE);
    } else {
        onAccessFineLocationPermissionGranted();
    }
}
 
Example #23
Source File: CheckInActivity.java    From StudentAttendanceCheck with MIT License 4 votes vote down vote up
private void initInstance() {

        setSupportActionBar(b.checkInActivityToolbar);

        TodayModule todayModule = TodayModule.getInstance();
        RealmResults<StudentModuleDao> studentModuleDao = todayModule.getTodayModule();

        int targetingModule = getIntent().getExtras().getInt("moduleItem");
        Log.i("CheckInActivity initInstance", String.valueOf(targetingModule));
        moduleLat = studentModuleDao.get(targetingModule).getLocLat();
        moduleLng = studentModuleDao.get(targetingModule).getLocLng();
        className = studentModuleDao.get(targetingModule).getRoom();

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();

        module_id = studentModuleDao.get(targetingModule).getModuleId();

        b.clickToAddModuleBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                Log.w("MY_LAT", String.valueOf(douMyLat));
                Log.w("MY_LNG", String.valueOf(douMyLng));
                Log.w("MO_LAT", String.valueOf(moduleLat));
                Log.w("MO_LNG", String.valueOf(moduleLng));

                LatLng moduleLocation = new LatLng(moduleLat, moduleLng);
                LatLng studentLocation = new LatLng(douMyLat, douMyLng);
//                checkInBounds = toBounds(moduleLocation, 432);
                checkInBounds = toBounds(moduleLocation, 1000);
                // 432 is the smallest radius from house to Coates

                Log.w("module Location", String.valueOf(moduleLocation));
                Log.w("student Location", String.valueOf(studentLocation));

//                if (checkInBounds.contains(new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude()))) {

                if (checkInBounds.contains(studentLocation)) {
                    initiatePopupWindow();
                } else {
                    Toast.makeText(CheckInActivity.this, "OUTBOUND", Toast.LENGTH_SHORT).show();
                }


            }
        });

        MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

    }
 
Example #24
Source File: MapActivity.java    From Hillffair17 with GNU General Public License v3.0 3 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);

    MapFragment mapFragment= (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);


}
 
Example #25
Source File: MapsEarthquakeMapActivity.java    From coursera-android with MIT License 2 votes vote down vote up
@Override
protected void onPostExecute(List<EarthQuakeRec> result) {

	// Get Map Object
	mMap = ((MapFragment) getFragmentManager().findFragmentById(
			R.id.map)).getMap();

	if (null != mMap) {

		// Add a marker for every earthquake

		for (EarthQuakeRec rec : result) {

			// Add a new marker for this earthquake
			mMap.addMarker(new MarkerOptions()

					// Set the Marker's position
					.position(new LatLng(rec.getLat(), rec.getLng()))

					// Set the title of the Marker's information window
					.title(String.valueOf(rec.getMagnitude()))

					// Set the color for the Marker
					.icon(BitmapDescriptorFactory
							.defaultMarker(getMarkerColor(rec
									.getMagnitude()))));

		}

		// Center the map 
		// Should compute map center from the actual data
		
		mMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(
				CAMERA_LAT, CAMERA_LNG)));

	}
		
	if (null != mClient)
		mClient.close();

}