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 27.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 5 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.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
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 onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationTextView = findViewById(R.id.locationTextView);
Button recordLocationButton = findViewById(R.id.recordLocationButton);
Button viewLocationsButton = findViewById(R.id.viewLocationsButton);
ListView locationListView = findViewById(R.id.locationListView);
// Initialize Location Manager
locationManager =(LocationManager) getSystemService(LOCATION_SERVICE);
// Set up ListView adapter
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, locationList);
locationListView.setAdapter(adapter);
// Record location button functionality
recordLocationButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
getLocation();
}
});
// View saved locations button functionality
viewLocationsButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
adapter.notifyDataSetChanged();
Toast.makeText(MainActivity.this, "Showing saved locations", Toast.LENGTH_SHORT).show();
}
});
}
private void getLocation(){
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)!= PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},1);
return;
}
locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, new LocationListener(){
@Override
public void onLocationChanged(@NonNull Location location){
String locationText = "Lat: "+ location.getLatitude()+", Lon: "+ location.getLongitude();
locationTextView.setText(locationText);
locationList.add(locationText);
Toast.makeText(MainActivity.this, "Location Recorded", Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!