add fucking Map

This commit is contained in:
Matthias Schreiner 2019-06-23 17:36:43 +03:00
parent 5027665009
commit acda3e7328
3 changed files with 145 additions and 4 deletions

View File

@ -1,25 +1,128 @@
package at.fhj.swd.dailyhelper.ui.fragemnt;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.maps.android.clustering.ClusterManager;
import java.util.List;
import at.fhj.swd.dailyhelper.R;
public class MapFragment extends Fragment {
public class MapFragment extends Fragment implements OnMapReadyCallback, GoogleMap.OnInfoWindowClickListener {
View view;
private MapView mapView;
private GoogleMap map;
private UiSettings mUiSettings;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_map, container, false);
view = inflater.inflate(R.layout.fragment_map, container, false);
mapView = view.findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
return view;
}
}
private void enableMyLocation() {
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
if(map != null) {
map.setMyLocationEnabled(true);
}
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.setOnInfoWindowClickListener(this);
mUiSettings = map.getUiSettings();
// Setting Map View
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// UI controls
mUiSettings.setZoomControlsEnabled(true);
mUiSettings.setMapToolbarEnabled(true);
// Getting reference to rg_views of the layout activity_main
RadioGroup rgViews = (RadioGroup) view.findViewById(R.id.rg_views);
// Defining Checked Change Listener for the RadioGroup
RadioGroup.OnCheckedChangeListener checkedChangeListener = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// Currently checked is rb_map
if(checkedId==R.id.rb_map){
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
// Currently checked is rb_satellite
if(checkedId==R.id.rb_satellite){
map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
}
}
};
// Setting Checked ChangeListener
rgViews.setOnCheckedChangeListener(checkedChangeListener);
enableMyLocation();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onDestroy() {
mapView.onDestroy();
super.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
public void onInfoWindowClick(Marker marker) {
;
}
}

View File

@ -1,14 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ly_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_orange_light">
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/rg_views">
</com.google.android.gms.maps.MapView>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Karte, Aktuelle Position, GPS Koordinaten"
android:textSize="80px"/>
android:textSize="30dp"/>
<RadioGroup
android:id="@+id/rg_views"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:background="@color/cardview_light_background">
<RadioButton
android:id="@+id/rb_map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/map"
android:textSize="20dp"
android:checked="true" />
<RadioButton
android:id="@+id/rb_satellite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/satellite"
android:textSize="20dp"/>
</RadioGroup>
</RelativeLayout>

View File

@ -14,5 +14,7 @@
<string name="google_maps_key">AIzaSyBQhcmDlyP01yNwTd4RTlatQIAJH3wJHw0</string>
<string name="map">Karte</string>
<string name="satellite">Satelit</string>
</resources>