Реализовать getMapAsync() в классе

337
14 февраля 2017, 18:19

Есть активити в которой реализую метод getMap(), но так как он depricated я его не могу реализовать в полной мере. Нашёл несколько вариантов решения данной проблемы, одним из них было реализовать вместо него метод getMapAsync() после чего имплементировать интерфейс OnMapReadyCallback, вместе с ним появляется метод onMapReady. Проблема в том, что не знаю что конкретно туда впихнуть (думаю сами маркеры, но они у меня взаимосвязаны в onCreate) и самое главное как правильно модифицировать мой класс. Подскажите как быть.

public class MainActivity extends Activity {
    private ViewGroup infoWindow;
    private TextView infoTitle;
    private TextView infoSnippet;
    private Button infoButton;
    private OnInfoWindowElemTouchListener infoButtonListener;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final MapFragment mapFragment = (MapFragment)getFragmentManager().findFragmentById(R.id.map);
        final MapWrapperLayout mapWrapperLayout = (MapWrapperLayout)findViewById(R.id.map_relative_layout);
        final GoogleMap map = mapFragment.getMap();
        // MapWrapperLayout initialization
        // 39 - default marker height
        // 20 - offset between the default InfoWindow bottom edge and it's content bottom edge
        mapWrapperLayout.init(map, getPixelsFromDp(this, 39 + 20));
        // We want to reuse the info window for all the markers,
        // so let's create only one class member instance
        this.infoWindow = (ViewGroup)getLayoutInflater().inflate(R.layout.info_window, null);
        this.infoTitle = (TextView)infoWindow.findViewById(R.id.title);
        this.infoSnippet = (TextView)infoWindow.findViewById(R.id.snippet);
        this.infoButton = (Button)infoWindow.findViewById(R.id.button);
        // Setting custom OnTouchListener which deals with the pressed state
        // so it shows up
        this.infoButtonListener = new OnInfoWindowElemTouchListener(infoButton,
            getResources().getDrawable(R.drawable.round_but_green_sel), //btn_default_normal_holo_light
            getResources().getDrawable(R.drawable.round_but_red_sel)){ //btn_default_pressed_holo_light
            @Override
            protected void onClickConfirmed(View v, Marker marker) {
                // Here we can perform some action triggered after clicking the button
                Toast.makeText(MainActivity.this, marker.getTitle() + "'s button clicked!", Toast.LENGTH_SHORT).show();
            }
        };
        this.infoButton.setOnTouchListener(infoButtonListener);

        map.setInfoWindowAdapter(new InfoWindowAdapter() {
            @Override
            public View getInfoWindow(Marker marker) {
                return null;
            }
            @Override
            public View getInfoContents(Marker marker) {
                // Setting up the infoWindow with current's marker info
                infoTitle.setText(marker.getTitle());
                infoSnippet.setText(marker.getSnippet());
                infoButtonListener.setMarker(marker);
                // We must call this to set the current marker and infoWindow references
                // to the MapWrapperLayout
                mapWrapperLayout.setMarkerWithInfoWindow(marker, infoWindow);
                return infoWindow;
            }
        });
        // Let's add a couple of markers
        map.addMarker(new MarkerOptions()
                .title("India")
                .snippet("New Delhi")
                .position(new LatLng(20.59, 78.96)));
        map.addMarker(new MarkerOptions()
                .title("Prague")
                .snippet("Czech Republic")
                .position(new LatLng(50.08, 14.43)));
        map.addMarker(new MarkerOptions()
                .title("Paris")
                .snippet("France")
                .position(new LatLng(48.86,2.33)));
        map.addMarker(new MarkerOptions()
                .title("London")
                .snippet("United Kingdom")
                .position(new LatLng(51.51,-0.1)));
    }
    public static int getPixelsFromDp(Context context, float dp) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int)(dp * scale + 0.5f);
    }
}
READ ALSO
Как отслеживать перемотку ListView

Как отслеживать перемотку ListView

Это мой класс наследованный от SimpleCursorAdapterЗаливаю базу данных в listview

438
Как не терять фокус?

Как не терять фокус?

Дело в том что у меня есть Видео Плеер использую библиотеку и перед ним ImageView, то есть типа баннера, которая закрывает 30% видеоплеераКаждые...

307
Чтение данных из Socket без задержки

Чтение данных из Socket без задержки

Имеется приложение, логика которого следующая: 1) Приложение подключается к серверу2) При нажатии на кнопку приложение читает данные от сервера

315
Стили для подменю

Стили для подменю

Проблема в том, что на сайте написан на wordpress не получается задать чтобы пункт подменю был ниже самого основного менюКогда я задаю отступ...

240