Add one more Empty Activity to your project and name it LocationServicesActivity
Add one more button to start_activity.xml and implement its click event listener in ActivityStart.java to open this activity (steps to add button and implement event listener are similar to those you have done so far for the other buttons).
public void viewLocationServices(View view) {
Intent intent = new Intent(this, LocationServicesActivity.class);
startActivity(intent);
}
3. Open build.gradle (Module) and add the following dependency for google play services location then click Sync Now.
implementation 'com.google.android.gms:play-services-location:21.0.1'
4. Open activity_location_services.xml and add 3 TextView and 1 Button widgets with the IDs below to get GPS coordinates (Latitude and Longitude) and street address.
5. Since the sample code for location services and places are long (see them in Week 3 lecture slides), I add them to two separate classes, and you only need to call methods from those to implement the tutorial. Download two Java files MyLocationPlace.java and MyLocationPlaceMap.java from Canvas and add (or drag and drop) them to the first package in the java folder as seen below.
6. Open both Java files in Android Studio and verify that the first line in each of them is the same as that in MainActivity.java file. If it is not, copy the first line from MainActivity.java to them. This line is to add the two java class files are included in your project. If your project name is Mobile Tech App, the first line should be:
package com.example.mobiletechapp;
7. Open LocationServicesActivity.java, place the following libraries above the LocationServicesActivity class
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import java.util.ArrayList;
8. Declare the following variables (inside the LocationServicesActivity class and above the onCreate method).
MyLocationPlaceMap myLocationPlaceMap;
ArrayList<MyLocationPlace> myLocations = new ArrayList<>();
MyLocationPlace myLocation;
9. Initialise these variables in the onCreate method (place below the setContentView method)
myLocationPlaceMap = new MyLocationPlaceMap(getApplicationContext(), LocationServicesActivity.this);
myLocationPlaceMap.requestPermissions();
myLocationPlaceMap.getLatLngAddress(myLocations);
10. Add the following click event listener to LocationServicesActivity.java (place it below the onCreate method)
public void showCurrentLocation(View view) {
myLocationPlaceMap.getLatLngAddress(myLocations);
TextView tvlat = findViewById(R.id.textViewLatitude);
TextView tvlng = findViewById(R.id.textViewLongitude);
TextView tvaddr = findViewById(R.id.textViewStreetAddress);
if (myLocations.size() > 0) {
myLocation = myLocations.get(0);
myLocations.clear();
tvlat.setText("Latitude: " + myLocation.getLatitude());
tvlng.setText("Longitude: " + myLocation.getLongitude());
tvaddr.setText("Address: " + myLocation.getAddress());
}
}
See the screenshot below and verify the code you have added to the LocationServicesActivity class
11. To display the GPS location on screen, the user needs to click the Show Last Known/Current Location button. Open activity_location_services.xml, select the Show Last Known/Current Location button, find onClick in the Attributes panel then select the showCurrentLocation method.
12. Run your project then do the following steps to request the device’s location access.
13. If you run this app on a real (physical) phone and press the Show Last Known/Current Location button, it will show you your current location and street address. You can move to different locations (home, shopping centres, UC, etc.) to check them on your app.
14. However, if you run the app on an emulator, it does not use current location of your computer. Android Studio provides virtual locations to test your app, so you can follow the steps below to open Extended Controls and set a virtual location on the emulator map to the last known/current location.
15. You can tap another place on the emulator map, look at its GPS location, click Set Location button then click the Show Last Known/Current Location button on the emulator to display the GPS location and street address.
Use Places to find GPS coordinates and street addresses for nearby places
In the next steps, you will use Places library to find nearby places (the business or points of interests near the current location).
16. Open build.Gradle (Module:app) and add the Places library to the dependencies and click Sync Now
implementation 'com.google.android.libraries.places:places:3.0.0'
17. Open MapsActivity.java and declare the following instance in the MapsActivity class
MyLocationPlaceMap myLocationsPlaces;
18. Add the following to the onCreate method (below mapFragment.getMapAsync(this);)
myLocationsPlaces = new MyLocationPlaceMap(getApplicationContext(), MapsActivity.this);
19. In the onMapReady method, comment out the code for Sydney marker and call the getNearbyPlaces method as
myLocationsPlaces.getNearbyPlaces(mMap, "YOUR_API_KEY");
20. Replace YOUR_API_KEY with the API Key you placed in the AndroidManifest.xml before.
21. Run the project and click the View Google Map button. You will see 5 blue markers as follows (assuming the current location remains the same as above, that is 303 E Hedding St, San Jose, CA 95112, USA)
Laser tattoo removal works by delivering short pulses of high intensity laser light which break down the tattoo https://aglsclinic.com/for-men/complimentary-consultation/ ink particles. Over a series of treatments the body's immune system clears away the fragmented ink gradually lightening or completely removing the tattoo.