Question: Hello I made a simple gps code using android studio api 2 7 . The last expert I gave this too did it wrong! please
Hello I made a simple gps code using android studio api The last expert I gave this too did it wrong! please tweak this code so after you record your current location, it should show your Ip address and then you can click a button to name the location ip address that was recorded and rate it out of and then it will be added to the past locations and then you can see a list of all countries recorded and its ratings! Here is my code. I want the code to remain functional and simple. please just the code below and build upon it Please make the xml file colorful
mainactivity.java:
package com.example.simplegpsapp;
import android.Manifest;
import android.content.pmPackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.osBundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity
private TextView locationTextView;
private LocationManager locationManager;
private final ArrayList locationList new ArrayList;
private ArrayAdapter adapter;
@Override
protected void onCreateBundle savedInstanceState
super.onCreatesavedInstanceState;
setContentViewRlayout.activitymain;
locationTextView findViewByIdRidlocationTextView;
Button recordLocationButton findViewByIdRidrecordLocationButton;
Button viewLocationsButton findViewByIdRidviewLocationsButton;
ListView locationListView findViewByIdRidlocationListView;
Initialize Location Manager
locationManager LocationManager getSystemServiceLOCATIONSERVICE;
Set up ListView adapter
adapter new ArrayAdapterthis android.Rlayout.simplelistitem locationList;
locationListView.setAdapteradapter;
Record location button functionality
recordLocationButton.setOnClickListenernew View.OnClickListener
@Override
public void onClickView v
getLocation;
;
View saved locations button functionality
viewLocationsButton.setOnClickListenernew View.OnClickListener
@Override
public void onClickView v
adapter.notifyDataSetChanged;
Toast.makeTextMainActivitythis, "Showing saved locations", Toast.LENGTHSHORTshow;
;
private void getLocation
if ActivityCompatcheckSelfPermissionthis Manifest.permission.ACCESSFINELOCATION PackageManager.PERMISSIONGRANTED &&
ActivityCompat.checkSelfPermissionthis Manifest.permission.ACCESSCOARSELOCATION PackageManager.PERMISSIONGRANTED
ActivityCompat.requestPermissionsthis new StringManifestpermission.ACCESSFINELOCATION;
return;
locationManager.requestSingleUpdateLocationManagerGPSPROVIDER, new LocationListener
@Override
public void onLocationChanged@NonNull Location location
String locationText "Lat: location.getLatitude Lon: location.getLongitude;
locationTextView.setTextlocationText;
locationList.addlocationText;
Toast.makeTextMainActivitythis, "Location Recorded", Toast.LENGTHSHORTshow;
@Override
public void onStatusChangedString provider, int status, Bundle extras
@Override
public void onProviderEnabled@NonNull String provider
@Override
public void onProviderDisabled@NonNull String provider
null;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
