본문 바로가기

Development/Android

[Android] Google Maps Android API v2 간단 사용법


아래의 내용들은 여기 내용을 보고 참고하였습니다.



GoogleMap 컴포넌트 가져오기

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
 
android:id="@+id/map"
 
android:name="com.google.android.gms.maps.MapFragment"
 
android:layout_width="match_parent"
 
android:layout_height="match_parent" />
private GoogleMap mMap;
...
mMap
= ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();


Map 타입 정의

GoogleMap map;
...
// Sets the map type to be "hybrid"
map
.setMapType(GoogleMap.MAP_TYPE_HYBRID);


Map  타입 종류

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.



마커추가하기

mMap.addMarker(new MarkerOptions()
       
.position(new LatLng(0, 0))
       
.title("Hello world"));

움직이게 가능한 마커는 아래와 같이 하면된다.

static final LatLng PERTH = new LatLng(-31.90, 115.86);
Marker melbourne = mMap.addMarker(new MarkerOptions()
                         
.position(PERTH)
                         
.draggable(true));

마커의 옵셥은 아래와 같다.

Position (Required)
The LatLng value for the marker's position on the map. This is the only required property for a Marker object.
Anchor
The point on the image that will be placed at the LatLng position of the marker. This defaults to the middle of the bottom of the image.
Alpha
Sets the opacity of the marker. Defaults to 1.0.
Title
A string that's displayed in the info window when the user taps the marker.
Snippet
Additional text that's displayed below the title.
Icon
A bitmap that's displayed in place of the default marker image. You can't change the icon once you've created the marker.
Draggable
Set to true if you want to allow the user to move the marker. Defaults to false.
Visible
Set to false to make the marker invisible. Defaults to true.
Flat or Billboard orientation
By default, markers are oriented against the screen, and will not rotate or tilt with the camera. Flat markers are oriented against the surface of the earth, and will rotate and tilt with the camera. Both types of markers do not change size based on zoom. Use GroundOverlays if you desire this effect.
Rotation
The orientation of the marker, specified in degrees clockwise. The default position changes if the marker is flat. The default position for a flat marker is north aligned. When the marker is not flat, the default position is pointing up and the rotation is such that the marker is always facing the camera.


색상 정하기

static final LatLng MELBOURNE = new LatLng(-37.813, 144.962);
Marker melbourne = mMap.addMarker(new MarkerOptions()
                         
.position(MELBOURNE)
                         
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));

투명도 주기

static final LatLng MELBOURNE = new LatLng(-37.813, 144.962);
Marker melbourne = mMap.addMarker(new MarkerOptions()
                         
.position(MELBOURNE)
                         
.alpha(0.7f));

이미지 넣기

  private static final LatLng MELBOURNE = new LatLng(-37.813, 144.962);
 
private Marker melbourne = mMap.addMarker(new MarkerOptions()
                           
.position(MELBOURNE)
                           
.title("Melbourne")
                           
.snippet("Population: 4,137,400")
                           
.icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));