Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Use this in your layout:</strong></p> <pre><code>&lt;LinearLayout android:id="@+id/map_container2" android:layout_width="match_parent" android:layout_height="200dp" android:layout_weight="35.22" android:orientation="horizontal" &gt; &lt;fragment android:id="@+id/map1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" class="com.google.android.gms.maps.SupportMapFragment" map:cameraTargetLat="40.72" map:cameraTargetLng="-74.00" map:cameraZoom="8" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>And this code:</strong></p> <pre><code>onCreate{ setUpMapIfNeeded(); } private void setUpMapIfNeeded() { // TODO Auto-generated method stub // 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. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map1)) .getMap(); // Check if we were successful in obtaining the map. if (mMap != null) { setUpMap(); } } } private void setUpMap() { // TODO Auto-generated method stub // Hide the zoom controls as the button panel will cover it. mUiSettings = mMap.getUiSettings(); // Enables/disables zoom gestures (i.e., double tap, pinch &amp; stretch). mMap.getUiSettings().setZoomGesturesEnabled(false); // Enables/disables scroll gestures (i.e. panning the map). mMap.getUiSettings().setScrollGesturesEnabled(false); // Enables/disables the compass (icon in the top left that indicates the orientation of the // map). mMap.getUiSettings().setCompassEnabled(false); // Add lots of markers to the map. addMarkersToMap(); // Pan to see all markers in view. // Cannot zoom to bounds until the map has a size. final View mapView = getSupportFragmentManager().findFragmentById(R.id.map1).getView(); if (mapView.getViewTreeObserver().isAlive()) { mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressLint("NewApi") // We check which build version we are using. @Override public void onGlobalLayout() { LatLngBounds bounds = new LatLngBounds.Builder() .include(WOODS) .build(); if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.ICE_CREAM_SANDWICH) { mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50)); } }); } } private void addMarkersToMap() { // TODO Auto-generated method stub // Uses a colored icon. mWoods = mMap.addMarker(new MarkerOptions() .position(WOODS) .title("Woods") .snippet("R. Quatá, 1016, Vila Olimpia - (11) 3849-6868") .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload