-4

I am new with maps in android i have this code :

enter codepublic class MapsActivity extends FragmentActivity implements GoogleMap.OnMyLocationButtonClickListener,
    GoogleMap.OnMyLocationClickListener,
    OnMapReadyCallback {

private GoogleMap mMap;
Button req_button;
String[] lat;
String[] lon;
String[] id;
String[] emails;
double latitude,lonitude;
int result_search,StatusChange_customer;
String params_search ,Status_cheked_customer,params_checked_customer,Status_cheked_customer_rating;
public Handler mHandler;
Location location;
@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.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    Intent intent1 = getIntent();
    lat = intent1.getStringArrayExtra("latitute");
    lon  = intent1.getStringArrayExtra("longitude");
    id = intent1.getStringArrayExtra("id");
    emails  = intent1.getStringArrayExtra("emails");
    latitude=intent1.getDoubleExtra("MyLat",0);
    lonitude=intent1.getDoubleExtra("MyLon",0);
    req_button =(Button)findViewById(R.id.R_id);
    this.mHandler = new Handler();

    this.mHandler.postDelayed(m_Runnable,5000);

}

private final Runnable m_Runnable = new Runnable()
{
    public void run()

    {

        Search_for_Accepted_Job();
        Toast.makeText(MapsActivity.this,"in runnable",Toast.LENGTH_SHORT).show();

        MapsActivity.this.mHandler.postDelayed(m_Runnable, 10000);
    }

};

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    LatLng [] sydeny = new LatLng[lat.length];
    mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    // Add a marker in Sydney and move the camera
    for (int i=0 ; i< lat.length;i++) {
        sydeny[i] = new LatLng(Double.parseDouble(lat[i]), Double.parseDouble(lon[i]));

    }
    for (int i=0 ; i< sydeny.length;i++) {
        mMap.addMarker(new MarkerOptions().position(sydeny[i]).title(emails[i]+ " " + id[i]));
      //  mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydeny[i], 5));
    }
   LatLng sydeny1 = new LatLng(latitude,lonitude);
    mMap.addMarker(new MarkerOptions().position(sydeny1).title("Your location" ));
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydeny1, 5));*/

   mMap.setMyLocationEnabled(true);
    mMap.setOnMyLocationButtonClickListener(this);
    mMap.setOnMyLocationClickListener(this);



}



public void Request(View view) {

    Toast.makeText(this," Request",Toast.LENGTH_SHORT).show();
  for (int i=0; i< lat.length;i++)
    {

            send_request(id[i]);

    }
    req_button.setEnabled(false);
}


@Override
public boolean onMyLocationButtonClick() {
    Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT).show();
    return false;
}

@Override
public void onMyLocationClick(@NonNull Location location) {
    Toast.makeText(this, "Current location:\n" + location, Toast.LENGTH_LONG).show();
    lonitude=location.getLatitude();
    lonitude=location.getLongitude();
} 

So this code take a latitude and longitude from another activity and present them in Map , recently i tried to implement two interfaces (GoogleMap.OnMyLocationButtonClickListener GoogleMap.OnMyLocationClickListener) and i get my location with blue circle in map and change at real time with me and there is a method named

 public void onMyLocationClick(@NonNull Location location) {
    Toast.makeText(this, "Current location:\n" + location, Toast.LENGTH_LONG).show(); 

my Question is how to use the latitude and longitude of this method , i mean how to get the latitude and longitude of my location because it is correct i i will need it to calculate the distance between me and other places .

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
ahmad
  • 145
  • 1
  • 7
  • Give me the link of the same question !!!! , it is the second question been rejected from you , i do not think you read the question carefully – ahmad Nov 15 '17 at 07:39

1 Answers1

0

To correctly use location in your app, you need to handle asking user permission to turn on location in settings (in case it is turned off) and then follow the steps in the documentation: https://developer.android.com/training/location/retrieve-current.html

To answer your question exactly, did you try location.getLatitude() and location.getLongitude()?

  • sure i tried it , but Location.getLatitude() does not work with real time tracking , this interfaced gave my exact location with accurate lat and lot but the problem i do not know how to use this values – ahmad Nov 15 '17 at 07:41
  • https://developer.android.com/training/location/receive-location-updates.html you need to implement this to receive real time updates – Sindhura Katta Nov 15 '17 at 22:36