0
다른보기 나 액티비티에지도를 표시하기 위해 사용자 정의보기를 만들었습니다. 하지만 Google지도 앱처럼 프레임에서 간단한 클릭을 얻고 싶습니다. 누구든지 나를 도울 수 있습니까?지도에서 onClickListener 추가 CustomView
사용자 정의보기있다 : 나는 XML의 사용 방법
public class MapView extends FrameLayout {
private Subject<GoogleMap> mapSubject;
private static final float MAP_ZOOM_LEVEL_STATIC = 12.0f;
private Circle mCircle;
public MapView(@NonNull Context context) {
super(context);
init(context, null);
}
public MapView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public MapView(@NonNull Context context, @Nullable AttributeSet attrs,
@AttrRes int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
SupportMapFragment mapFragment = SupportMapFragment.newInstance();
if (!isInEditMode()) {
FragmentTransaction fragmentTransaction =((AppCompatActivity)context)
.getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(getId(), mapFragment);
fragmentTransaction.commit();
mapSubject = BehaviorSubject.create();
Observable.create((ObservableOnSubscribe<GoogleMap>) e -> mapFragment.getMapAsync(e::onNext))
.subscribe(mapSubject);
mapSubject.subscribe(googleMap -> mCircle = googleMap.addCircle(new
CircleOptions().center(new LatLng(0.0f, 0.0f)).radius(0)));
}
}
/**
* Update position and create a new Circle and move camera to new position
*
* @param location The location to be updated.
*/
public void updatePosition(LatLng location) {
mapSubject.subscribe(googleMap -> {
mCircle.remove();
mCircle = googleMap.addCircle(new
CircleOptions().center(location).radius(15)
.strokeWidth(10)
.strokeColor(Color.RED)
.fillColor(Color.RED));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location,
MAP_ZOOM_LEVEL_STATIC));
});
}
/**
* This method is responsible to add a polyline in google maps
*
* @param results array with directions
*/
public void addPolyline(DirectionsResult results) {
if(results != null) {
mapSubject.subscribe(googleMap -> {
List<LatLng> decodedPath =
PolyUtil.decode(results.routes[0]
.overviewPolyline
.getEncodedPath());
googleMap.addPolyline(new
PolylineOptions()
.addAll(decodedPath)
.width(10)
.color(Color.RED)
.geodesic(true));
updatePosition(decodedPath.get(0));
});
}
}
}
: 디버거에서 여기에 통과하지 않았기 때문에 내가 성공하지 (클릭을 식별하기 위해 노력하고있어 방법
<com.name.of.package.custom_view.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
그게 전부) :
MapView mapView = (MapView)findViewById(R.id.mapView)
mapView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toogle(view);
Toast.makeText(mContext, "Map clicked!", Toast.LENGTH_SHORT).show();
}
});
당신이 안드로이드를 사용해보십시오 않았다 = clickeable "true"로? – diegoveloper
나는 tryed하지만 didnt 작업 ... –