마커, 반경원 추가하기
java)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | package com.ghj.blog_038; import android.graphics.Color; import android.support.v4.app.FragmentActivity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.CircleOptions; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; public class MainActivity extends FragmentActivity implements OnMapReadyCallback { //GoogleMap 객체 GoogleMap googleMap; //위도 경도 final static double mLatitude = 37.5197889; //위도 final static double mLongitude = 126.9403083; //경도 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //맵생성 SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map); //콜백클래스 설정 mapFragment.getMapAsync(this); } //구글맵 생성 콜백 @Override public void onMapReady(GoogleMap googleMap) { this.googleMap = googleMap; //지도타입 - 일반 this.googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); //기본위치(63빌딩) LatLng position = new LatLng(mLatitude , mLongitude); //화면중앙의 위치와 카메라 줌비율 this.googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 14)); onAddMarker(); } //마커 , 원추가 public void onAddMarker(){ LatLng position = new LatLng(mLatitude , mLongitude); //나의위치 마커 MarkerOptions mymarker = new MarkerOptions() .position(position); //마커위치 // 반경 1KM원 CircleOptions circle1KM = new CircleOptions().center(position) //원점 .radius(1000) //반지름 단위 : m .strokeWidth(0f) //선너비 0f : 선없음 .fillColor(Color.parseColor("#880000ff")); //배경색 //마커추가 this.googleMap.addMarker(mymarker); //원추가 this.googleMap.addCircle(circle1KM); } } | cs |
xml)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment android:id="@+id/map" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="wrap_content" android:name="com.google.android.gms.maps.SupportMapFragment"/> </LinearLayout> | cs |
AndroidManifest.xml)
1 2 3 | <!-- Google Map --> <meta-data android:name="com.google.android.geo.API_KEY" android:value="" /> | cs |
결과
'IT > - 프로그래밍' 카테고리의 다른 글
안드로이드 리스트 다이얼로그 예제 (0) | 2016.11.24 |
---|---|
안드로이드 구글맵3 마커, 정보창 클릭 이벤트 (4) | 2016.11.23 |
안드로이드 구글맵1 구글맵 띄우기 (8) | 2016.11.21 |
정보보안기사 리눅스 로그파일 (0) | 2016.11.19 |
안드로이드 두지점(위도,경도) 사이의 거리 (0) | 2016.11.18 |