Using GPS to get current location i just use this following code But i dont get a Toast msg Like My current location is:?

StackOverflow https://stackoverflow.com/questions/7766778

  •  09-02-2021
  •  | 
  •  

문제

Using GPS to get current location i just use this folowing code But i dont get a Toast msg ?

i just want to massage Like " My current location is: "

LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

    LocationListener mlocListener = new MyLocationListener();

    mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);

    }

    /* Class My Location Listener */

    public class MyLocationListener implements LocationListener

    {

    public void onLocationChanged(Location loc)

    {

    loc.getLatitude();

    loc.getLongitude();

    String Text = "My current location is: " + "Latitud = " + loc.getLatitude() +"Longitud = "  + loc.getLongitude();

    Toast.makeText( getApplicationContext(),Text,Toast.LENGTH_SHORT).show();

    }

    @Override

    public void onProviderDisabled(String provider)

    {

    Toast.makeText( getApplicationContext(),"Gps Disabled",Toast.LENGTH_SHORT ).show();

    }

    @Override

    public void onProviderEnabled(String provider)

    {

    Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();

    }

    @Override

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

    {

    }
도움이 되었습니까?

해결책

Go to the Eclipse Toolbar Click on Window-> Show view -> DDMS -> Emulator control in the emulator control manually enter location Longitude and Latitude , then check hope it works fine !!!

다른 팁

your code is fine but if you are testing on device you need to move your device out in open space and if you are testing on emulator you need to provide kml file for mock locations.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top