코틀린에서 구글맵 가져다 쓰려고 하는데
xml에서 누구는 Fragment 쓰고 누구는 MapView 가져다 쓰고 또 누구는 FragmentContainerView를 가져다 쓰는데...
MapView를 가져다 쓰면 화면이 안 나오고
Fragment를 가져다 쓰면 해당 뷰를 찾을 수가 없다고 나와서 계속 안 된다...
예를들어
<Fragment
````android:id="@+id/GoogleMap"
````~~/>
해놓고 비하인드 코드 가서
binding.GoogleMap 하거나 R.id.GoogleMap 하면 선언되지 않은거라며 찾지를 못 하는데 어떻게 함?
---- UI ----
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
|
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@color/TermicaGrey"
>
<LinearLayout
android:id="@+id/llHeader"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/GoogleMaps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<ImageButton
android:id="@+id/ibMenu"
android:layout_width="35dp"
android:layout_height="30dp"
android:src="@drawable/ic_button_menu"
android:background="@android:color/transparent"
android:padding="2dp"
android:scaleType="center"
android:transitionName="slide_right_enter"
/>
</LinearLayout>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/GoogleMaps"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/llHeader"
app:layout_constraintBottom_toTopOf="@id/llFooter"
/>
<LinearLayout
android:id="@+id/llFooter"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
android:gravity="center"
>
<Button
android:id="@+id/btnSend"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@drawable/ic_button_square_corner"
android:text="테스트 버튼"
android:textSize="50dp"
android:textColor="@color/black"
android:textAlignment="textStart"
android:fontFamily="@font/gmarket_sans_ttf_medium"
/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
|
cs |
23개의 댓글
무분별한 사용은 차단될 수 있습니다.
닉네임대충짓
Fragment 쓸거면 FragmentContainerView를 권장하고
걍 맵뷰만 써도 상관은 없음
MapVIew써서 화면이 안나오는건 사용법 맞게 못쓴 것 같고
밑에껀 <Fragment /> 말고 <fragment /> 해보기
집에가게해줘
아.. 저건 내가 잘 못쓴거야 소문자로 fragment 했음.
mapview 같은 경우는
val mapView = binding.GoogleMaps
mapView?.getMapAsync{googleMap ->
googleMap.mapType = GoogleMap.MAP_TYPE_NORMAL
val seoul = LatLng(37.5519, 126.9918)
googleMap.addMarker(
MarkerOptions().position(seoul).title("Marker in Seoul")
)
googleMap.moveCamera(CameraUpdateFactory.newLatLng(seoul))
}
이렇게 썻는데 그냥 아무 화면도 안 나오더라고..
닉네임대충짓
api키 넣었믐?
집에가게해줘
ㅇㅇ Manifest에
<meta-data
````android:name="com.google.android.maps.v2.API_KEY"
````android:value="~~~"/>
하고 넣었어
그런데 인터넷에 찾오빈까 다른 사람들은 키를 안 넣었을 때 좌측 하단에 Google 마크는 나오는데 화면이 안 나오고
나는 Google마크 조차도 안 나오더라고..
닉네임대충짓
음.. 그럼 ui 풀코드좀
닉네임대충짓
아니면 맵뷰말고 그 자리를 그대로 이미지뷰, background red 같은걸로 해서 맞는위치에 들어갔는지 봐도될듯 ui이상한거같은데
집에가게해줘
아 본문에 추가한건 FragmentContainerView 사용 버전이야!
집에가게해줘
ImageView로 background black 해봤지만 화면에서는 잘 나옴
집에가게해줘
본문에 추가했어
닉네임대충짓
저긴 문제 없어보이네...
git이라도 있으면 공유해주면 전체코드 한번 보면 좋겠는데
집에가게해줘
이거 공유하면 API_KEY도 공유 되는데 빼면 당연히 동작을 안 하고... 이럴 땐 어떻게 함?
그냥 나중에 API_KEY를 수정해버리면 되려나??
닉네임대충짓
뺴고공유해주면 전체코드라도 볼 수 있을듯?
집에가게해줘
https://github.com/Lee-IDLE/NotYet
그냥 나중에 삭제해버리고 다시 만들어서 쓰지 뭐...
닉네임대충짓
인터넷 퍼미션 선언이 안됐다 개붕아
집에가게해줘
미안 밥 먹느라...
혹시 지금 됨?
닉네임대충짓
엉? 인터넷 퍼미션 넣고도 안됨?
집에가게해줘
아아 미안! 잘못봤어...
퍼미션 얘기보고 "어? 리포지토리 공개 아닌가??" 하고 들어가서 봤는데
다른 리포지토리 보고서 "아 비공개였네"하고 변경하고 말한거였어.. ㅜㅜ 해볼께
닉네임대충짓
사실 안돌려봤음나도 ㅎㅎ 인터넷 퍼미션이 일단 있긴 해야됨
그리고 이제 돌려보려고 들어오는데 빌드도 안되는걸 올려놨네;; 빌드는 되게해서 올려줘
닉네임대충짓
그리고 R import 해놓은게 잘못됐네
import android.R 지워
닉네임대충짓
내가 고쳐서 맵 뜨는거 봤는데, 브랜치에 올려줌
닉네임대충짓
올리는건 권한이 없구나 ㅋㅋ
인터넷 퍼미션 추가
import android.R 제거
FragmentContainerView 사용
하면됨
집에가게해줘
아 ㅅㅂ R 뭐야 하아....
내가 뭘 추가시키려고 하다가 실수로 R에서 멈췄나? R로 시작하는게 뭐가 있다고 하려고 한거지
아 ㅅㅂ ㅋㅋㅋ 너무 고맙다 ㅜㅜ
URA!!
안드로이드 손 뗀지 오래되서 가물가물한데 MapView 가 삽입이 안된거같은데.
니 기존코드 보면 MapView 만 만들고 그걸 부모가 될 뷰에 삽입하지 않음.