What I am trying to do is to make a google maps app in which I can move the map and the marker position stays centered (DONE), something like Uber. Then after the push of a button (buttonGPS) get the lat (tvValueLatitude) and long (tvValueLatitude) coordinates to display in two textview (DONE). I need help hidding the blue dot while leaving the button in the top right, also getting the coordinates from where I put the grey marker at when moving the map. enter image description here Next is the xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<RelativeLayout
android:id="@+id/rlmap"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/rlData">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/pin"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rlData"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<LinearLayout
android:id="@+id/llGPS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:divider="?android:dividerHorizontal"
android:orientation="horizontal"
android:showDividers="middle">
<Button
android:id="@+id/buttonGPS"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_weight="1"
android:gravity="center"
android:text="Get GPS" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:layout_weight="1"
android:divider="?android:dividerVertical"
android:orientation="vertical"
android:showDividers="middle">
<TextView
android:id="@+id/tvLatitude"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/Latitude"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/Black"
/>
<TextView
android:id="@+id/tvValueLatitude"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:gravity="center"
android:hint="@string/valueLatitude"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/Black"
android:textColorHint="@color/Gray" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:layout_weight="1"
android:divider="?android:dividerVertical"
android:orientation="vertical"
android:showDividers="middle">
<TextView
android:id="@+id/tvLongitude"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/Longitude"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/Black"
/>
<TextView
android:id="@+id/tvValueLongitude"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:gravity="center"
android:hint="@string/valueLongitude"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/Black"
android:textColorHint="@color/Gray" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
The main activity
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback{
private GoogleMap mMap;
TextView lat,longt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
lat=findViewById(R.id.tvValueLongitude);
longt=findViewById(R.id.tvValueLatitude);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney, Australia, and move the camera.
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
So far I just have the map. Any help with coding or pointing a good tutorial would be great, thanks!