1. Download our Official Android App: Forums for Android!

Apps Displaying User's Actual Location

Discussion in 'Android Development' started by MizoRedDevil, Mar 8, 2011.

  1. MizoRedDevil

    MizoRedDevil Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Mar 8, 2011

    Mar 8, 2011
    1
    0
    5
    Hi,
    I'm a new coming in the world of android, I wanted to make a simple application that can display my location in real time , but i can't have a result here's my code :

    import android.app.Activity;
    import android.content.Context;
    import android.location.Location;
    import android.location.LocationListener;
    import android.location.LocationManager;
    import android.location.LocationProvider;
    import android.os.Bundle;
    import android.widget.Toast;
    public class SampleGPS extends Activity
    {
    private LocationManager locationManager;
    private LocationListener locationListener;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    System.out.println("etape une");
    locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    System.out.println("etape deux");
    locationListener = new MyLocationListener();
    System.out.println("etape trois");
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
    System.out.println("etape quatre");
    }
    private class MyLocationListener implements LocationListener
    {
    public void onLocationChanged(Location loc)
    {
    System.out.println("Position Changed");
    if (loc != null)
    {
    Toast.makeText(getBaseContext(), "Localisation actuelle :\n Lat: " + loc.getLatitude() + " Lng: " + loc.getLongitude(),Toast.LENGTH_SHORT).show();
    }
    }
    public void onProviderDisabled(String provider)
    {
    System.out.println(provider+" Est D
     

    Advertisement

  2. takeshi

    takeshi Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    3,354
    Joined:
    Dec 6, 2009

    Dec 6, 2009
    3,354
    283
    163
    You really should post this in a developer forum.
     
  3. ScorpDX

    ScorpDX Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,642
    Joined:
    Feb 7, 2010

    Feb 7, 2010
    1,642
    376
    163
    I do some stuff and get paid for it...that's all t
    Dallas/Fort Worth
    App already exists...Google Latitude!
     
  4. JamTheMan

    JamTheMan Well-Known Member
    Rank:
    None
    Points:
    38
    Posts:
    136
    Joined:
    Dec 16, 2010

    Thats rather simple, isn't it..? You have already set it up so it prints

    Code (Text):
    1.  
    2. System.out.println(provider+" Est D
     

Share This Page

Loading...