com.vuw.project1.riverwatch.ui.History_ActivityFragment_Map.java Source code

Java tutorial

Introduction

Here is the source code for com.vuw.project1.riverwatch.ui.History_ActivityFragment_Map.java

Source

//*H****************************************************************************
// FILENAME:   History_ActivityFragment_Map.java
//
// DESCRIPTION:
//  fragment for the map in the history
//
//  A list of names of copyright information is provided in the README
//
//    This file is part of RiverWatch.
//
//    RiverWatch is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    RiverWatch is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with RiverWatch.  If not, see <http://www.gnu.org/licenses/>.
//
// CHANGES:
// DATE         WHO       DETAILS
// 20/11/1995   George   Added header.
//
//*H*

package com.vuw.project1.riverwatch.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.vuw.project1.riverwatch.R;

/**
 * Created by James on 8/10/2016.
 */

public class History_ActivityFragment_Map extends Fragment implements OnMapReadyCallback {

    GoogleMap mGoogleMap;
    MapView mapView;

    View mView;

    static History_ActivityFragment_Map newInstance(double latitude, double longitude) {
        History_ActivityFragment_Map fragment = new History_ActivityFragment_Map();
        Bundle bundle = new Bundle();
        bundle.putDouble("latitude", latitude);
        bundle.putDouble("longitude", longitude);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MapsInitializer.initialize(getContext());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //        Inflate the layout for this fragment
        mView = inflater.inflate(R.layout.activity_history_map, container, false);
        return mView;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mapView = (MapView) mView.findViewById(R.id.map);
        if (mapView != null) {
            // Initialise the MapView
            mapView.onCreate(null);
            mapView.onResume();
            // Set the map ready callback to receive the GoogleMap object
            mapView.getMapAsync(this);
        }

    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        MapsInitializer.initialize(getContext());

        mGoogleMap = googleMap;
        mGoogleMap.addMarker(new MarkerOptions()
                .position(new LatLng(getArguments().getDouble("latitude"), getArguments().getDouble("longitude"))));
        mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
                new LatLng(getArguments().getDouble("latitude"), getArguments().getDouble("longitude")), 14));
    }
}