Nothing returned ?!

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Nothing returned ?!

Postby NachtNebel » Sun Mar 06, 2011 9:42 am

Hi everyone,

First of all, sorry for my bad english... Well, I just did a little programm supposed to calculate my GPS location, but it only shows my location once, and as soon as I move, it does on the "onStatusChanged" method and never calculates my position again... and I wanted to know why...

Here's my code:
Code: Select all
package com.pIndus.gps;

import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class Loc extends Activity {
   /** Called when the activity is first created. */
   
   private long refreshTime = 1000;
   private LocationManager mLocManager;
   private LocationListener mLocListener;
   
   @Override
   public void onCreate(Bundle savedInstanceState)
   {

      super.onCreate(savedInstanceState);

      setContentView(R.layout.main);

      /* Use the LocationManager class to obtain GPS locations */

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

       mLocListener = new MyLocationListener();

      mLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, this.refreshTime, 0, mLocListener);

   }

   /* Class My Location Listener */

   public class MyLocationListener implements LocationListener

   {

      
      @Override
      public void onLocationChanged(Location loc)
   
      {

         loc.getLatitude();

         loc.getLongitude();

         String Text = "Localisation courante:\n " + "Latitude : " + loc.getLatitude() + "\n" + "Longitude : " + loc.getLongitude();
         
         Log.i("GPS", "Localisation calculée");

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

      }

      @Override
      public void onProviderDisabled(String provider)
      {

         Toast.makeText( getApplicationContext(), "Gps désactivé", Toast.LENGTH_SHORT ).show();
         Log.i("GPS", "GPS Desactivé");

      }

      @Override
      public void onProviderEnabled(String provider)
      {

         Toast.makeText( getApplicationContext(),"Gps activé", Toast.LENGTH_SHORT).show();
         Log.i("GPS", "GPS Activé");

      }

      @Override
      public void onStatusChanged(String provider, int status, Bundle extras)
      {
         Toast.makeText( getApplicationContext(),"Statut changé", Toast.LENGTH_SHORT).show();
         Log.i("GPS", "Statut changé");
      }
      
      
   }
   
   public void onPause()
   {
      mLocManager.removeUpdates(mLocListener);
      super.onPause();
   }
   
   public void onStop()
   {
      mLocManager.removeUpdates(mLocListener);
      super.onStop();
   }




}


Does anyone see a big mistake which could cause this ?
NachtNebel
Freshman
Freshman
 
Posts: 2
Joined: Sun Mar 06, 2011 9:39 am

Top

Re: Nothing returned ?!

Postby NachtNebel » Sun Mar 06, 2011 10:05 am

Sorry double post
NachtNebel
Freshman
Freshman
 
Posts: 2
Joined: Sun Mar 06, 2011 9:39 am

Top

Return to Map Problems

Who is online

Users browsing this forum: Exabot [Bot] and 4 guests