package com.outlier.br.sos_carro.activity.OficinaActivity;
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.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.outlier.br.sos_carro.R;
import com.outlier.br.sos_carro.model.Oficina;
/**
* Created by daniel on 9/18/16.
*/
public class TabLocalizacaoFragments extends Fragment {
MapView mMapView;
private GoogleMap googleMap;
Oficina oficina;
public void setOficina(Oficina oficina) {
this.oficina = oficina;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab_oficina_localizacao, container, false);
mMapView = (MapView) rootView.findViewById(R.id.mapview);
mMapView.onCreate(savedInstanceState);
mMapView.onResume(); // needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
mMapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap mMap) {
googleMap = mMap;
// For dropping a marker at a point on the Map
LatLng latLng = new LatLng(oficina.getLatitude(), oficina.getLongitude());
MarkerOptions options = new MarkerOptions()
.position(latLng)
.title(oficina.getNome())
.snippet(oficina.getDescricao());
/*
carro = new MarkerOptions()
.position(latLng)
.title("Minha posiçao");*/
googleMap.addMarker(options);
// For zooming automatically to the location of the marker
CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(15).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
});
return rootView;
}
}
Thanks in advance for your help