Thẻ

, ,

1. Hiển thị map

– Để hiển thị được map ta cần MapFragment sau:

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment" />

– Ở trong code ta quản lý nó bằng đối tượng GoogleMap

//..
	private GoogleMap map;
//..
		map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
				.getMap();

Làm cách này cũng được, nhưng thường người ta sử dụng cách sau hơn, đó là sử dụng hàm getMapAsync và inplement OnMapReadyCallback

public class MainActivity extends Activity implements OnMapReadyCallback{
    private GoogleMap map;
//..
    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
//...
@Override
public void onMapReady(GoogleMap map) {
    this.map = map;
    Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
            .title("Hamburg"));
    Marker kiel = map.addMarker(new MarkerOptions()
            .position(KIEL)
            .title("Kiel")
            .snippet("Kiel is cool")
            .icon(BitmapDescriptorFactory
                    .fromResource(R.drawable.ic_launcher)));
    // Move the camera instantly to hamburg with a zoom of 15.
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
    // Zoom in, animating the camera.
    map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}

Map types
Sử dụng phương thức: map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
Normal
Typical road map. Roads, some man-made features, and important natural features such as rivers are shown. Road and feature labels are also visible.
Hybrid
Satellite photograph data with road maps added. Road and feature labels are also visible.
Satellite
Satellite photograph data. Road and feature labels are not visible.
Terrain
Topographic data. The map includes colors, contour lines and labels, and perspective shading. Some roads and labels are also visible.
None
No tiles. The map will be rendered as an empty grid with no tiles loaded.

2. Markers – Các điểm trên Map

Advertisements