gps beefup

fukurou

Administrator
Java:
import android.Manifest;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Switch;
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.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

public class MapsActivity extends FragmentActivity implements LocationListener {
    final int ACCESS_FINE_LOCATION =1;
    final int ACCESS_COARSE_LOCATION =1;
    Location myLocation; // to static var
    LocationManager locationManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        setPointer();
    }

    private void setPointer() {
        //get location service (system service)
        getGPSPermission(); // ask for permission by code for API 6 and above
        locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        //set location updates
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        locationManager.requestLocationUpdates(getCriteria(), 10, 50, this);
        //locationManager.getLastKnownLocation(getCriteria()); //get the last known location
    }

    private void getGPSPermission() {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {

            new AlertDialog.Builder(this)
                    .setTitle("gps Permission needed to use gps jutsu")
                    .setMessage("This permission is needed because the app needs to be able to use maps")
                    .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ActivityCompat.requestPermissions(MapsActivity.this,
                                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, ACCESS_FINE_LOCATION);
                        }
                    })
                    .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    })
                    .create().show();

        } else {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, ACCESS_FINE_LOCATION);

        }

    }

    public String getCriteria()
    {
        Criteria criteria = new Criteria(); //indicates criteria for selction on location provider
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(true);
        criteria.setBearingRequired(true);

        //get our best provider
        String bestProvicer =  locationManager.getBestProvider(criteria,true);// if false best GPS service will be wokend and used
        // if true only the gps wifi or gprs that are lit
        return bestProvicer;
    }
    @Override
    public void onLocationChanged(Location location) {
        this.myLocation=location;
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }

    @Override
    public void onProviderEnabled(String provider) {

    }

    @Override
    public void onProviderDisabled(String provider) {

    }
    public String placeToast(LatLng myLocation)
    {
        // convert gps coordinates into place name
        String returnString = "";
        Geocoder gcdLocale = new Geocoder(this); //new Geocoder(this, Locale.ENGLISH)
        List<Address> localeAdd = null;
        try {
            localeAdd = gcdLocale.getFromLocation(myLocation.latitude,myLocation.longitude,1);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //if localeAdd is null (false) get out of the function (method)
        assert localeAdd != null;
        if (localeAdd.size()>0)
        {
            String myAdd = localeAdd.get(0).getAddressLine(0);
            Toast.makeText(this, myAdd, Toast.LENGTH_LONG).show();
            returnString=myAdd;
        }
        return returnString;
    }

}
 

fukurou

Administrator
Java:
package com.yotamarker.gps2020;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

    LocationManager locationManager;
    LocationListener locationListener;

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {

                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i("Location","hiiiiiiiiiiiiiiiiiiiiiiii");
        locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

        locationListener = new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                Log.i("Location","lat: " + location.getLatitude() + "lon: " + location.getLongitude());
            }

            @Override
            public void onStatusChanged(String s, int i, Bundle bundle) {

            }

            @Override
            public void onProviderEnabled(String s) {

            }

            @Override
            public void onProviderDisabled(String s) {

            }
        };

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},1);
        } else {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5, 1, locationListener);

        }
    }
}
this gets the location at the get go and with each x meters moved
 

fukurou

Administrator
coordinates to location name kotlin
Java:
fun placeToast(myLocation:LatLng):String {
  // convert gps coordinates into place name
  val returnString = ""
  val gcdLocale = Geocoder(this) //new Geocoder(this, Locale.ENGLISH)
  val localeAdd:List<Address> = null
  try
  {
    localeAdd = gcdLocale.getFromLocation(myLocation.latitude, myLocation.longitude, 1)
  }
  catch (e:IOException) {
    e.printStackTrace()
  }
  //if localeAdd is null (false) get out of the function (method)
  assert(localeAdd != null)
  if (localeAdd.size() > 0)
  {
    val myAdd = localeAdd.get(0).getAddressLine(0)
    returnString = myAdd
  }
  return returnString
}
 

fukurou

Administrator
Java:
// global vars :
var locationManager:LocationManager
var locationListener:LocationListener
// some gps function 1
fun onRequestPermissionsResult(requestCode:Int, @NonNull permissions:Array<String>, @NonNull grantResults:IntArray) {
  super.onRequestPermissionsResult(requestCode, permissions, grantResults)
  if (grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
  {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) === PackageManager.PERMISSION_GRANTED)
    {
      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener)
    }
  }
}
protected fun onCreate(savedInstanceState:Bundle) {
  super.onCreate(savedInstanceState)
  setContentView(R.layout.activity_main)
// some gps stuff 2
  locationManager = this.getSystemService(Context.LOCATION_SERVICE) as LocationManager
  locationListener = object:LocationListener() {
    fun onLocationChanged(location:Location) {
      Log.i("Location", "lat: " + location.getLatitude() + "lon: " + location.getLongitude()) // modify hya
    }
    fun onStatusChanged(s:String, i:Int, bundle:Bundle) {
    }
    fun onProviderEnabled(s:String) {
    }
    fun onProviderDisabled(s:String) {
    }
  }
  if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !== PackageManager.PERMISSION_GRANTED)
  {
    ActivityCompat.requestPermissions(this, arrayOf<String>(Manifest.permission.ACCESS_FINE_LOCATION), 1)
  }
  else
  {
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5, 1, locationListener)
  }
}
 

fukurou

Administrator
public class Tokoro {
public static double lat = 51.4061;
public static double lon = 30.0571;
public static String placeName = "pripyat";
}

******************************

kotlin

object Tokoro {
var lat = 51.4061
var lon = 30.0571
var placeName = "pripyat"
}
 

fukurou

Administrator
it's so fucking cold out, but I gottan take go perform an experiment.
jizzes I hate foids and humans so much.
 
Top