New Microsoft Word Document PDF
New Microsoft Word Document PDF
package com.example.mygooglemapapp;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import android.Manifest;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CircleOptions;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
fab = findViewById(R.id.fab);
// Obtain the SupportMapFragment and get notified when the map is ready to be
used.
upportMapFragment mapFragment = (SupportMapFragment)
S
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In
this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be
prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the
user has
* installed Google Play services and returned to the app.
*/
@ Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
fab.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),
R.drawable.ic_visibility) );
// Sets the map type to be "hybrid"
Map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
m
} else if (mMap.getMapType() == GoogleMap.MAP_TYPE_NORMAL){
fab.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),
R.drawable.ic_visibility_off));
// Sets the map type to be "normal"
Map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
m
}
}
});
mMap.setOnMyLocationButtonClickListener(onMyLocationButtonClickListener);
mMap.setOnMyLocationClickListener(onMyLocationClickListener);
enableMyLocationIfPermitted();
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.setMinZoomPreference(11);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions,
@NonNull int[] grantResults) {
switch (requestCode) {
case LOCATION_PERMISSION_REQUEST_CODE: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
enableMyLocationIfPermitted();
} else {
showDefaultLocation();
}
return;
}
}
}
mMap.setMinZoomPreference(12);
circleOptions.radius(200);
circleOptions.fillColor(Color.RED);
circleOptions.strokeWidth(6);
mMap.addCircle(circleOptions);
}
};
}
?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:con******************xml code****************
<text=".MapsActivity">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:clickable="true"
android:src="@drawable/ic_visibility"
app:backgroundTint="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />