本文整理汇总了Java中com.google.android.gms.maps.MapFragment.getMap方法的典型用法代码示例。如果您正苦于以下问题:Java MapFragment.getMap方法的具体用法?Java MapFragment.getMap怎么用?Java MapFragment.getMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.maps.MapFragment
的用法示例。
在下文中一共展示了MapFragment.getMap方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: zoomToPad
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
private void zoomToPad( final Pad pad )
{
if( pad != null && pad.latitude != null && pad.longitude != null )
{
LatLng pos = new LatLng( pad.latitude, pad.longitude );
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentByTag( MAP_FRAGMENT_TAG );
if( mapFragment != null )
{
GoogleMap map = mapFragment.getMap();
if( map != null )
{
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom( pos, PAD_ZOOM );
map.animateCamera( cameraUpdate );
}
}
}
}
示例2: getMap
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
/**
* Get the map from the map fragment.
* @return The GoogleMap in the select_location_activity_map fragment.
*/
GoogleMap getMap() {
FragmentManager fm = getFragmentManager();
MapFragment fragment = (MapFragment) fm.findFragmentById(R.id.select_location_activity_map);
GoogleMap map = fragment.getMap();
return map;
}
示例3: setUpMapIfNeeded
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
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 mapFragment = ((MapFragment) this.getFragmentManager().findFragmentById(R.id.map));
mMap = mapFragment.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
} else {
Log.e("MockLocation", "Could not get map");
}
}
}
示例4: onCreate
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
fileDownloader = new FileDownloader(this);
MapFragment mapFragment = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
if(savedInstanceState == null){
mapFragment.setRetainInstance(true);
} else {
initialMoveDone = true;
map = mapFragment.getMap();
}
}
示例5: onCreate
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set default preference values.
PreferenceManager.setDefaultValues(this, PREF_FILE, MODE_PRIVATE, R.xml.preferences, false);
// Bind this activity to the background service.
bindService(new Intent(this, NmeaRelayService.class), nmeaRelayServiceConn,
Context.BIND_IMPORTANT | Context.BIND_AUTO_CREATE);
// Initialize UI.
setContentView(R.layout.activity_main);
final MapFragment mf = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
googleMap = mf.getMap();
googleMap.getUiSettings().setCompassEnabled(false);
googleMap.getUiSettings().setRotateGesturesEnabled(false);
googleMap.getUiSettings().setTiltGesturesEnabled(false);
if (savedInstanceState == null) {
// When the application starts for the first time, device
// connectivity may not be known.
// Let's update connectivity status right now.
ConnectivityListener.checkIfNetworkIsReady(this);
// Center map view on current device location.
final LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
Location loc = lm.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
if (loc == null) {
// Current device location is unknown: let's use a default one.
loc = new Location(LocationManager.PASSIVE_PROVIDER);
loc.setLatitude(48.82333);
loc.setLongitude(2.33667);
}
centerOnLocation(loc, false);
}
}
示例6: onCreate
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
@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));
}
示例7: setUpMapIfNeeded
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
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);
}
}
}
示例8: loadVendor
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
private void loadVendor() {
list = new VendorProductListFragment();
getFragmentManager().beginTransaction()
.replace(R.id.contentFrame, list).commit();
getFragmentManager().executePendingTransactions();
map_fragment = (MapFragment) getFragmentManager().findFragmentById(R.id.vendor_map);
map = map_fragment.getMap();
map.addMarker(new MarkerOptions().position(vendor.location).title(vendor.name)).getId();
CameraUpdate center=
CameraUpdateFactory.newLatLng(vendor.location);
CameraUpdate zoom=CameraUpdateFactory.zoomTo(13);
map.moveCamera(center);
map.animateCamera(zoom);
setTitle(vendor.name);
((TextView) findViewById(R.id.vendor_description)).setText(vendor.description);
if("".equals(vendor.contact_name)) {
findViewById(R.id.contact_name).setVisibility(View.GONE);
findViewById(R.id.contact_name_label).setVisibility(View.GONE);
} else {
((TextView) findViewById(R.id.contact_name)).setText(vendor.contact_name);
}
if("".equals(vendor.email)) {
findViewById(R.id.email).setVisibility(View.GONE);
findViewById(R.id.email_label).setVisibility(View.GONE);
} else {
((TextView) findViewById(R.id.email)).setText(vendor.email);
}
StringBuilder address = new StringBuilder(5);
address.append(vendor.city).append(", ").append(vendor.state).append(" ").append(vendor.zip);
((TextView) findViewById(R.id.street_address)).setText(vendor.street);
((TextView) findViewById(R.id.rest_address)).setText(address.toString());
if("".equals(vendor.location_description)) {
findViewById(R.id.location_description).setVisibility(View.GONE);
} else {
((TextView) findViewById(R.id.location_description)).setText(vendor.location_description);
}
ImageButton navigation = (ImageButton) findViewById(R.id.map_button);
navigation.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String encoded_string = String.format(Locale.ENGLISH, "%s, %s %s %s", vendor.street, vendor.city, vendor.state, vendor.zip);
String uri = String.format(Locale.ENGLISH, "geo:0,0f?q=%s",
encoded_string);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}
});
Iterator<VendorProduct> product_iterator = vendor.products.iterator();
while(product_iterator.hasNext()) {
list.addItem(product_iterator.next());
}
}
示例9: onCreate
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (VendorListFragment) getFragmentManager().findFragmentById(R.id.list);
map_fragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
map = map_fragment.getMap();
markerMap = new HashMap<String, Object>();
CameraUpdate center=
CameraUpdateFactory.newLatLng(new LatLng(43.897888, -122.722887));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(6);
map.moveCamera(center);
map.animateCamera(zoom);
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
openVendor((Vendor) markerMap.get(marker.getId()));
return true;
}
});
Ion.with(this).load("http://seagrant-staging-api.osuosl.org/1/vendors")
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
JsonArray vendors = result.getAsJsonArray("vendors");
Iterator<JsonElement> vendor_array = vendors.iterator();
while(vendor_array.hasNext()) {
Vendor vendor = new Vendor(vendor_array.next().getAsJsonObject());
markerMap.put(map.addMarker(new MarkerOptions()
.position(vendor.location).title(vendor.name)).getId(), vendor);
list.addItem(vendor);
}
}
});
}
示例10: onCreate
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo);
setupActionbar(getActionBar());
Bundle extras = getIntent().getExtras();
Parcelable[] parcelableArray = extras.getParcelableArray(ARG_PHOTOS_ARRAY);
markerPhotoMap = new HashMap<Marker, Photo>(parcelableArray.length);
photos = new ArrayList<Photo>(parcelableArray.length);
for (Parcelable parcelable : parcelableArray)
photos.add((Photo) parcelable);
viewPager = (ViewPager) findViewById(R.id.viewPager);
viewPager.setPageTransformer(true, new PhotoPageTransformer());
viewPager.setAdapter(new PhotoPagerAdapter(getFragmentManager(), photos));
viewPager.setOnPageChangeListener(this);
// if activity just launched, show photo selected by user
if (savedInstanceState == null)
{
viewPager.setCurrentItem(extras.getInt(ARG_SELECTED_INDEX));
findViewById(R.id.fragmentMap).setVisibility(View.GONE);
}
else
{
int visibility = savedInstanceState.getInt(STATE_MAP_VISIBILITY, View.GONE);
//noinspection ResourceType
findViewById(R.id.fragmentMap).setVisibility(visibility);
if (savedInstanceState.getBoolean(STATE_FULLSCREEN))
enableFullscreen();
}
setPhotoTitleAndAuthor(getActionBar(), photos.get(viewPager.getCurrentItem()));
if (MiscUtils.isGooglePlayAvailable(this))
{
mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.fragmentMap);
if (mapFragment.getMap() != null)
setupMap(mapFragment.getMap());
}
}
示例11: onCreate
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, true, false, true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.fake_google_maps_layout);
List<GpsZone> zones = GpsZoneDAO.getInstance(this).getAllZones();
Bundle extras = getIntent().getExtras();
if (extras != null) {
if (extras.containsKey(EXTRA_START_LOC)) {
mInitLatLng = extras.getParcelable(EXTRA_START_LOC);
}
}
getSupportActionBar().setTitle("Set fake zone");
// mRadiusText = (TextView)findViewById(R.id.radius_text);
// mSeekBar = (SeekBar)findViewById(R.id.radius_seekbar);
// mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
// @Override
// public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// mRadiusValue = (progress * 10 + 20);
// setRadiusText(mRadiusValue);
// insertCircle();
// }
//
// @Override
// public void onStartTrackingTouch(SeekBar seekBar) {}
//
// @Override
// public void onStopTrackingTouch(SeekBar seekBar) {}
// });
mMapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mMap = mMapFragment.getMap();
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
placeMarkerOnMap(latLng);
}
});
if (mInitLatLng != null) {
mMap.animateCamera (CameraUpdateFactory.newLatLngZoom (mInitLatLng, 13.0f));
}
for (GpsZone z : zones) {
putZoneOnMap(z);
}
}
示例12: onCreate
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_map);
// initialize icon drawables
locIcon = R.drawable.bluedot;
schoolIcon = R.drawable.university;
workIcon = R.drawable.workoffice;
beerIcon = R.drawable.beergarden;
// initialize the map
if(googleMap == null)
{
// get the map fragment and the map object
mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
googleMap = mapFragment.getMap();
// make sure the map exists before using
if(googleMap != null)
{
// setup the map objects
setupObjects();
// set the location
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(camOriginal));
// click listener
googleMap.setOnMapClickListener(new OnMapClickListener()
{
@Override
public void onMapClick(LatLng loc)
{
updateMapFromClick(loc);
}
});
}
}
}
示例13: onCreate
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Populate the navigation drawer data
drawerItems = getResources().getStringArray(R.array.drawer_array);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerList = (ListView) findViewById(R.id.left_drawer);
// Add the shadow over the main frame
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// Set up the drawer's list view
drawerList.setAdapter(new DrawerArrayAdapter(this, drawerItems));
drawerList.setOnItemClickListener(new DrawerItemClickListener());
// Enable action bar icon to toggle navigation drawer
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
// Set up ActionBar toggler
drawerToggle = new ActionBarDrawerToggle(this,
drawerLayout,
R.string.drawer_open,
R.string.drawer_close);
drawerLayout.setDrawerListener(drawerToggle);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
// Add the map to the content frame
if (findViewById(R.id.content_frame) != null) {
// Don't create the map if resuming from a saved state
if (savedInstanceState != null) {
return;
}
GoogleMapOptions options = new GoogleMapOptions();
MapFragment mapFragment = MapFragment.newInstance(
options.zoomControlsEnabled(false));
getFragmentManager().beginTransaction()
.add(R.id.content_frame, mapFragment, "map").commit();
map = mapFragment.getMap();
}
}
示例14: initializeMap
import com.google.android.gms.maps.MapFragment; //导入方法依赖的package包/类
/**
* Creates the GoogleMap canvas on the top of the Activity
* This map is used to set the localisation of the cinema or the museum
*
* @param latitude
* @param longitude
*/
private void initializeMap(double latitude, double longitude) {
if (googleMap == null) {
MapFragment fragment = (MapFragment) this.getFragmentManager()
.findFragmentById(R.id.map);
googleMap = fragment.getMap();
LatLng latlng = new LatLng(latitude, longitude);
MarkerOptions marker = new MarkerOptions().position(latlng).title(
this.name);
googleMap.addMarker(marker);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latlng).zoom(16).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
ContextLocation cl = new ContextLocation();
cl.registerListener(this);
userLocation = cl.getLocation(this);
Location placeLocation = new Location("");
placeLocation.setLatitude(latitude);
placeLocation.setLongitude(longitude);
this.calculateDistance(userLocation, placeLocation);
}
}