Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- it
- error
- android
- 해석
- 번역
- 안드로이드
- 개발자
- javascript
- MySQL
- 개발
- server
- techEmpower
- NGINX
- unity
- centOS7
- 구글
- 한글
- caddy
- Portfolio
- C lanuage
- ubuntu
- 자바
- java
- kakao
- php
- 프래그먼트
- H2O
- mariadb
- C
- 컴퓨터과학총론
Archives
- Today
- Total
개발모음집
구글 검색 api 에러 본문
1. 참고 구글 개발자센터 이걸 보면서 장소자동완성텍스트를 만드려하는데
<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
/>
에서 Unresolved class 'PlaceAutocompleteFragment' 에러가 뜬다.
참고 스택오버플로우를 보니 '
compile 'com.google.android.gms:play-services-places:10.2.6'
를 해준다고 나온다. 에러해결!
2. Inconvertible types; cannot cast 'android.support.v4.app.Fragment' to 'com.google.android.gms.location.places.ui.PlaceAutocompleteFragment
PlaceAutocompleteFragment autocompleteFragment =
(PlaceAutocompleteFragment) getFragmentManager()
.findFragmentById(R.id.place_autocomplete_fragment);
참고 스택오버플로우를 보니 getActivity()를 붙여주라하니 에러해결
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getActivity().getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
전체 소스
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
SupportPlaceAutocompleteFragment autocompleteFragment = (SupportPlaceAutocompleteFragment)
getActivity().getSupportFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
// AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
// .setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
// .build();
// autocompleteFragment.setFilter(typeFilter);
// autocompleteFragment.setBoundsBias(new LatLngBounds(
// new LatLng(-33.880490, 151.184363),
// new LatLng(-33.858754, 151.229596)));
if(autocompleteFragment==null){
autocompleteFragment = (SupportPlaceAutocompleteFragment) SupportPlaceAutocompleteFragment.instantiate(getContext(), "com.google.android.gms.location.places.ui.SupportPlaceAutocompleteFragment");
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
Log.i("", "Place: " + place.getName());//get place details here
}
@Override
public void onError(Status status) {
}
});
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
Log.i("", "Place: " + place.getName());
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
Log.i("", "An error occurred: " + status);
}
});
}
return inflater.inflate(R.layout.fragment_search, container, false);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
xml
<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.SupportPlaceAutocompleteFragment"
/>
'Android' 카테고리의 다른 글
fcm 삽질 (0) | 2017.07.14 |
---|---|
Unable to add window -- token null is not for an application 에러 (0) | 2017.07.14 |
구글지도 위도, 경도값 받아오지못하는 에러 (2) | 2017.06.30 |
구글 Key Exists 에러 (0) | 2017.06.30 |
android FragmentTransaction, commit already called error (0) | 2017.06.29 |